In a registration form I allow the user to select several spoken languages and of course to minimize tomfoolery I am using selects. In the view I have: <%= select(''person'', ''language1'', LANGUAGES, options = {}) %> In my people_helper.rb I have: module PeopleHelper # constant for language selection in ''_form_background.rhtml'' LANGUAGES = %w{Akan Algerian Amharic Arabic ... Xhosa Yoruba Zulu } end However rails still complains, "uninitialized constant LANGUAGES." I can put it above my person.rb model but that is messy. Is there a better way? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
from what i know, and from what works for me, i put it in enviornment.rb file. as i understand, all of ruby''s constants are loaded when the server is first started, so enviornment.rb is the given place to put it. whether the theory, or logical structure is correct, i don''t know - - but it works great. (after restarting the server, obviously). hth, harp -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Worked perfectly. Thanks! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
That solution is still a little on the messy side (in terms of cluttering up environment.rb). In addition, you have the (admittedly very minor) overhead of initializing the array before any controller/action called, even though only the controller dealing with the Person model actually uses it. What I would do would be to create a languages.rb file in your lib directory with nothing in it except the constant definition. Then call "require ''languages''" at the top of the appropriate controller. In fact, if it is only used in one action, you can even call it just for that specific action: class PeopleController < ApplicationController ... def register require ''languages'' # whatever else your action needs @person = Person.new ... end ... end Just a different (and cleaner, in my opinion) way to do it. Hope this helps! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
That is a great solution. It definately makes sense to only initialize the array when it is needed and not globally. Every time you learn something, you realize there is always a better way right after you finish implementing the solution!!! Thanks to everyone who replied!!! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---