views:

39

answers:

3

i have my constants initialized in environment.rb like this :

 Rails::Initializer.run do |config|
  ...
  MAX_BID = 10
 end

i would like to use this constant in my models and views,what is the correct syntax? if a use it a model its says

 NameError: uninitialized constant User::MAX_BID

i understand that it is looking for the constant inside the model , how can i tell explicitly that this constant is in the environment? thanks

A: 

Maybe

Rails::MAX_BID
tommasop
still cant use it in a model
fenec
+1  A: 

Pull it outside the config block.

So do this instead:

Rails::Initializer.run do |config|
  ...
end

MAX_BID = 10
Tony Fontenot
still cant use it in a model
fenec
Then you have other issues... Did you restart the app after making the change to `environment.rb`? How are you referencing the constant (the actual line of code)? You could also try `::MAX_BID`.
Tony Fontenot
+1  A: 

You can use an initializer with all of your constants in /config/initializers/constants.rb

MAX_BID = 10
shingara