How to override “new” method for a rails model

后端 未结 7 562
南笙
南笙 2020-12-16 03:01

In my rails app I have a model with a start_date and end_date. If the user selects Jan 1, 2010 as the start_date and Jan 5, 2010 as the end_date, I want there to be 5 instan

相关标签:
7条回答
  • 2020-12-16 03:49

    I guess you want to set default values for your model attribute ?

    There's another solution than overriding ; you can set callbacks :

    class Model
    
    before_create :default_values
    def default_values
      ...
    end
    
    0 讨论(0)
提交回复
热议问题