assignable_values Show archive.org snapshot now lets you define a secondary default that is only used if the primary default value is not assignable:
class Song < ActiveRecord::Base
assignable_values_for :year, :default => 1999, :secondary_default => lambda { Date.today.year } do
(Date.today.year - 2) .. Date.today.year
end
end
If called in 2013 the code above will fall back to:
Song.new.year # => 2013
This is especially useful in authorization scenarios with Consul Show archive.org snapshot where you want powerful defaults for superusers, but don't want to make records invalid by default for users with lesser privileges.
Posted by Henning Koch to makandra dev (2012-08-02 15:27)