I have code similar to follwoing
...
@c = M.find(params[:id]).c.find(params[:c_id])
if @c.s.count > 0
@s = @c.s.sort_by{|e| e[:order]}.first
unless @s.p.nil?
@img = @s.p.image_file.remote_url
else
@s.p = P.new
@img = request.protocol + request.host_with_port + "/none.png"
end
unless @s.a.nil?
@voice = @s.a.audio_file.remote_url
else
@s.a = A.new
end
else
...
end
@c_v_url = ""
unless @c_v_url.nil?
@c_v_url = @c.v_o.a_file.remote_url
else
@c.v_o = A.new
end
@c_m_url = ""
unless @c_m_url.nil?
@c_m_url = @c.b_m.a_file.remote_url
else
@c.b_m = A.new
end
...
Now all the instance variables are to be used in the view and I want to re-factor the code to make the Controller skinny. What will be the best approach to do the re-factoring? Will it be wise to move this code to the Model?