Re: [Rails-core] Suggestion: default values for models

2012-10-18 Thread Gabriel Sobrinho
That is a problem for me either. I can't use before_save callback because I need to show the default value on forms. So, I have a date field and the default value is today, but when user open the form, today must be on that field. I'm setting this kind of default value on controller like

Re: [Rails-core] Suggestion: default values for models

2012-10-18 Thread Allen Madsen
This is relevant: http://stackoverflow.com/questions/328525/what-is-the-best-way-to-set-default-values-in-activerecord They mention using after_initialize. Allen Madsen http://www.allenmadsen.com On Thu, Oct 18, 2012 at 8:50 AM, Gabriel Sobrinho gabriel.sobri...@gmail.com wrote: That is a

Re: [Rails-core] Suggestion: default values for models

2012-10-18 Thread G. Sobrinho
Using a after initialize does not respect if you set the attribute to nil, like this: Payment.new(:due_date = nil) Also, it will mutate the already persisted objects if they are persisted using a nil due date for example. Another problem happens when you select specific attributes like:

Re: [Rails-core] Suggestion: default values for models

2012-10-18 Thread Matt Jones
On Oct 18, 2012, at 8:50 AM, Gabriel Sobrinho wrote: That is a problem for me either. I can't use before_save callback because I need to show the default value on forms. So, I have a date field and the default value is today, but when user open the form, today must be on that field.

Re: [Rails-core] Suggestion: default values for models

2012-10-18 Thread Alexander Kurakin
You can read here: https://github.com/FooBarWidget/default_value_for#when-not-to-use-default_value_for среда, 17 октября 2012 г., 23:41:55 UTC+4 пользователь Zamith написал: Isn't this just the same as having a before_save callback where you define these default values? Also, what do you

[Rails-core] Suggestion: default values for models

2012-10-17 Thread Alexander Kurakin
ROR doesn't realize functionality of setting default values for models. We can use db's default values but they are evaluated during migrations. We can't set default value i.e. Time.now. But there are completed gems that realize this. I.e. default_value_for

Re: [Rails-core] Suggestion: default values for models

2012-10-17 Thread Luís Ferreira
Isn't this just the same as having a before_save callback where you define these default values? Also, what do you mean with We can use db's default values but they are evaluated during migrations? On Oct 17, 2012, at 8:28 PM, Alexander Kurakin wrote: ROR doesn't realize functionality of