I\'m trying to find the best way to set default values for objects in Rails.
The best I can think of is to set the default value in the new
method in
If you are referring to ActiveRecord objects, you have (more than) two ways of doing this:
E.G.
class AddSsl < ActiveRecord::Migration
def self.up
add_column :accounts, :ssl_enabled, :boolean, :default => true
end
def self.down
remove_column :accounts, :ssl_enabled
end
end
More info here: http://api.rubyonrails.org/classes/ActiveRecord/Migration.html
E.G. before_validation_on_create
More info here: http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html#M002147