On May 28, 8:17 am, shenry <[email protected]> wrote:
> I have a constant.rb file in lib/ with:
>
> module Constants
>   FOO = %w( tastes great)
>   BAR = %w( less filling)
> end
>
> I'm able to access the constants fine in my Model, but I'm also using
> them to populate select boxes in a view and can't figure out how to
> make them available to the view.
>
> I've tried:
>
> require 'constants'
> class ApplicationController < ActionController::Base
>   include Constants
>   ....
>
> end
>
> as well as the same thing in the specific controller whose method is
> calling the offending action.
>
> Any advice on where to require the module? Thanks,
It's not to do with requiring (you can get rid of that require
'constants') it's to do with where the module is included.
You could just write Constants::FOO in your view.

Alternatively,

class ApplicationController < ActionController::Base
  include Constants
  helper Constants
end

might work (but slightly abusing the helper method)

Fred
> Stu
--~--~---------~--~----~------------~-------~--~----~
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]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to