before_save :maybe_set_source
def maybe_set_source
self[:source] = source_name if !self[:source]
end
def source
self[:source] || source_name
end
# The default value I want to set
def source_name
File.basename(RAILS_ROOT)
end
Really?
before_save :maybe_set_source
def maybe_set_source
self[:source] = source_name if !self[:source]
end
def source
self[:source] || source_name
end
# The default value I want to set
def source_name
File.basename(RAILS_ROOT)
end
try after_initialize http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html
ReplyDeletedef after_initialize
self[:source] ||= File.basename(RAILS_ROOT)
end