Zack Chandler
2006-Mar-24 16:47 UTC
[Rails] Where to put array to be shared across models.
Quick question: I have an array of reserved words that I want to share across most of my models so I can do something like this in the models: validates_exclusion_of :username, :in => RESERVED_WORDS, :message => "This username is a reserved word. Please choose another." Here is a sampling of the the array: RESERVED_WORDS = %w( blog blogs forum forums search login logout signup signout register help store ) Should I just subclass AR and then extend my models from this base class or is there a way to stick it in one of the config files like environment.rb? Thanks, Zack -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060324/855efb8a/attachment.html
Yes, you can put constants in environment.rb and they''ll be available everywhere. -- -- Tom Mornini On Mar 24, 2006, at 8:45 AM, Zack Chandler wrote:> Quick question: I have an array of reserved words that I want to > share across most of my models so I can do something like this in > the models: > > validates_exclusion_of :username, :in => RESERVED_WORDS, :message > => "This username is a reserved word. Please choose another." > > Here is a sampling of the the array: > RESERVED_WORDS = %w( blog blogs forum forums search login logout > signup signout register help store ) > > Should I just subclass AR and then extend my models from this base > class or is there a way to stick it in one of the config files like > environment.rb? > > Thanks, > Zack > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Zack Chandler
2006-Mar-24 17:44 UTC
[Rails] Where to put array to be shared across models.
Thanks Tom. I thought that would be the easiest. I just didn''t know if it is the "best practices" way to do it. Thanks again, Zack On 3/24/06, Tom Mornini <tmornini@infomania.com> wrote:> > Yes, you can put constants in environment.rb and they''ll be available > everywhere. > > -- > -- Tom Mornini > > On Mar 24, 2006, at 8:45 AM, Zack Chandler wrote: > > > Quick question: I have an array of reserved words that I want to > > share across most of my models so I can do something like this in > > the models: > > > > validates_exclusion_of :username, :in => RESERVED_WORDS, :message > > => "This username is a reserved word. Please choose another." > > > > Here is a sampling of the the array: > > RESERVED_WORDS = %w( blog blogs forum forums search login logout > > signup signout register help store ) > > > > Should I just subclass AR and then extend my models from this base > > class or is there a way to stick it in one of the config files like > > environment.rb? > > > > Thanks, > > Zack > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060324/cb3ef805/attachment-0001.html