Sha256: 8cf8db612c4ad36c18427d3d39a494b17a87f6445c2e18677e7bc79b446bf1ee
Contents?: true
Size: 1.66 KB
Versions: 1
Compression:
Stored size: 1.66 KB
Contents
# UnchangedValidator A validator for ActiveModels that checks that attributes have not been modified since the last time the model was saved. ## Installation Add this line to your application's Gemfile: ```ruby gem 'unchanged_validator' ``` And then execute: $ bundle Or install it yourself as: $ gem install unchanged_validator ## Running the tests Install various dependencies: $ appraisal install Then, to run the tests: $ appraisal rspec ## Usage ### Example ```ruby class Person < ActiveRecord::Base validates_unchanged :first_name end p = Person.new p.first_name = 'Bob' p.save #=> true p.valid? #=> true p.first_name = 'Dave' p.save #=> false p.valid? #=> false ``` ### I18n To change the default message for all usages of `validates_unchanged`: ```yaml # In config/locales/en.yml en: activerecord: errors: messages: changed: 'cannot be different' ``` To change the message for a particular attribute of a particular model: ```yaml # In config/locales/en.yml en: activerecord: models: person: attributes: first_name: changed: 'cannot be different' ``` ### Options UnchangedValidator supports all of the common `ActiveModel::Validations` options: ```ruby class Book < ActiveRecord::Base validates_unchanged :title, allow_blank: true validates_unchanged :author, allow_nil: true validates_unchanged :copyright_expirty_date, if: same_edition? validates_unchanged :published_date, message: 'cannot be re-released' validates_unchanged :foreward, on: :update validates_unchanged :publisher, unless: :rebranded? end ``` ## Supported Rails Versions * 3.1 * 3.2 * 4.0 * 4.1 * 4.2
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
unchanged_validator-1.0.0 | README.md |