ruby on rails - Using constant in model -


i'm trying define constant in initializer file , use model.

  • config/initializers/constants.rb

    default_event_duration = 15 
  • app/models/event.rb

    class event < activerecord::base    before_validation :set_end_and_allday    [...]    def set_end_and_allday     self.allday ||= false     self.end_event ||= self.start + default_event_duration.minute   end end 

however, when try create new event, displays following error in logs:

nameerror - uninitialized constant event::default_event_duration 

am doing wrong?

i've made searches on google, didn't find solution (except defining constant model , not in initializer... , that's not want do).

it scope problem: constant in root scope searching constant in controller scope.

a simple '::default_event_duration' solved issue.


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -