Why don't Helpers auto-refresh in development mode?

Hey there

I find it frustrating that my rails helps do not reload in development
mode

Any changes I make to a model are immediately reflected, but helper
changes require a server restart

Does anyone know a work around?

cheers

Helper definition is loaded on application load, but the evaluation is
done
on every request , which are you talking about ?

Thanks for replying, btw

Is there a hack I can do to cause it to reload the definition on every
request?

If I define “helpy” in my application_helper.rb file:

def helpy
return “something”
end

… and then change the return value between page refreshes, it is not
updated… I just get the original method definition loaded when
webrick server started

On Nov 15, 12:07pm, “[email protected][email protected]
wrote:

If I define “helpy” in my application_helper.rb file:

def helpy
return “something”
end

… and then change the return value between page refreshes, it is not
updated… I just get the original method definition loaded when
webrick server started

i’ve never noticed that before. What version of rails are you running?
Are you explicitly requiring any of your helper files?

fred

Radhames Brito wrote in post #961537:

Helper definition is loaded on application load, but the evaluation is
done
on every request , which are you talking about ?

Um…no. In development mode, the helper classes should be reloaded
with every request.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

On Mon, Nov 15, 2010 at 10:27 AM, Marnen Laibow-Koser
[email protected]wrote:

well, they dont, at least not on my apps, they get evaluated in every
request, but the definition does not change. I have test it on rails 2 ,
but
not rails 3, many times and they dont get reloaded in development.

Thats because the return value is part of the helper definition and the
definition is set when the app is loaded, normally one would evaluate
the
result and this would be updated on every request, thats why your
problem
seems strange, but is not strange is the default behavior, so what do
you do
? I have to go to work now so i cant fully explain but you have to
return a
lambda method if you want your result to be dynamic.

I’ll show a common example with the model on rails 2

name_scope :recent ,:conditions=>{ :create_at => 2.months.ago}

^^ the 2 month ago is set on app load and not changed as long as you
dont
restart the app, so a year from now will have the same value

name_scope :recent ,lambda {:conditions=>{ :create_at => 2.months.ago} }

^^ here the 2.month.ago is reevaluated on every call to the method

On Mon, Nov 15, 2010 at 8:38 AM, radhames brito [email protected]
wrote:

name_scope :recent ,:conditions=>{ :create_at => 2.months.ago}

^^ the 2 month ago is set on app load and not changed as long as you dont
restart the app, so a year from now will have the same value

name_scope :recent ,lambda {:conditions=>{ :create_at => 2.months.ago} }

^^ here the 2.month.ago is reevaluated on every call to the method

I want to clarify the highlighted part

What i understand is that rails.nerd has the return value in the helper
method’s definition, kind of like in this case the above is 2.month.ago
example.

Radhames Brito wrote in post #961601:

On Mon, Nov 15, 2010 at 10:27 AM, Marnen Laibow-Koser
[email protected]wrote:

Please quote when replying.

well, they dont, at least not on my apps, they get evaluated in every
request, but the definition does not change. I have test it on rails 2 ,
but
not rails 3, many times and they dont get reloaded in development.

I’ve never used Rails 3. With Rails 2 for me, helpers certainly do seem
to get reloaded.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

I have created a ticket for this on the Inherited Resources page

I just tested this in a new, fresh Rails project and the results are
different

Changes to a helper are immediately reflected

Turns out, “Inherited Resources” gem effects this behaviour… and
locks in your helpers when the server starts