On Tuesday, November 6, 2012 8:49:16 PM UTC, scottc wrote:
>
>
>
> I want to be able to display the results of this method on a View 
> called index.html.erb, so I include the following code in the 
> index_helper.rb file: 
>
>     module IndexHelper 
>       require 'HelloWorld' 
>     end 
>
> Also, I include the following code on the view index.html.erb: 
>
>     <%= @howdy %> 
>
> I've read where I need to include the following line in the /config/ 
> application.rb file: 
>
>     config.autoload_paths += %W(#{config.root}/lib 
>
> However, my preference is to load this module only when the View 
> renders the page, not when the Application loads. What am I missing? 
>
>
You're not so much missing  what the lib folder does as misunderstanding 
what modules do. As an aside, loading stuff on demand isn't thread safe so 
usually best avoided in production.
Just requiring a file doesn't do anything other than load that file. If you 
wanted to include a module then you'd need to do

module IndexHelper
  include HelloWorld
end

in fact in your controller you could 

helper HelloWorld

instead. Even this won't cause @howdy to be set - that would only be set 
when that hello method is called.

Fred

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/vlTVJ0DkdfoJ.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to