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 ?

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

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

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

fred

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

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,

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 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:

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,

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

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

http://github.com/josevalim/inherited_resources/issues/issue/95