Controller problems

Hello !

Another newbie question.

I have the following view

VIEW:

<% @jobs.each do |job| %>
<%i = job.duration.time%>
<%@deadline = job.created_on + i.days%>
<%if Time.now < @deadline%>

<%=job.name%> ... ... <%end%> <%end%>

and

CONTROLLER:

def show
@jobs = Job.find(:all)
end

Everything works fine, but shouldn’t the stuff in the view be in the
controller?If so, plz give me some hints. I tried many options and non
of them work. Thx!

Hi Pablo,

It seems like deadline pertains more to the model than to the
controller. Why not put something like the following into your Job
model?

def deadline
self.created_on + self.duration.days
end

If you do it this way, you have access to the job’s deadline wherever
you have access to a job.

Note that the value will be calculated every time you call the method.
That may or may not be efficient.