Read more

assignable_values 0.4.1 adds secondary default values

Henning Koch
August 02, 2012Software engineer at makandra GmbH

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
Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

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 17:27)