README.md in context_validations-0.0.2 vs README.md in context_validations-0.0.3

- old
+ new

@@ -2,23 +2,57 @@ [![Build Status](https://secure.travis-ci.org/dockyard/context_validations.png?branch=master)](http://travis-ci.org/dockyard/context_validations) [![Dependency Status](https://gemnasium.com/dockyard/context_validations.png?travis)](https://gemnasium.com/dockyard/context_validations) [![Code Climate](https://codeclimate.com/github/dockyard/context_validations.png)](https://codeclimate.com/github/dockyard/context_validations) -Rails exceptions automatically opened as issues on GitHub +Context based validations for model instances. ## Looking for help? ## If it is a bug [please open an issue on GitHub](https://github.com/dockyard/context_validations/issues). -## About ## +## Installation ## -Context based validations for model instances. +In your `Gemfile` -## Example ## +```ruby +gem 'context_validations' +``` +You can either mixin the moduels on a case-by-case basis or make the +changes global: + +### Case-by-case ### + ```ruby +# model +class User < ActiveModel::Base + include ContextValidations::Model +end + +# controller +class UsersController < ApplicationController + include ContextValidations::Controller +end +``` + +### Global ### +Create an initializer: `config/initializers/context_validations.rb` + +```ruby +class ActiveRecord::Base + include ContextValidations::Model +end + +class ActionController::Base + include ContextValidations::Controller +end +``` + +## Usage ## + +```ruby class UserController < ApplicationController include ContextValidations::Controller def create @user = User.new(user_params) @@ -83,11 +117,11 @@ ... end ``` ### Models ### -When the `ContextValidations::Model` module is mixed into the module all +When the `ContextValidations::Model` module is mixed into the model all of the validation callbacks are removed from that model. Because we are setting the validations on the instance you should not use `ActiveRecord::Base.create` as we do not want to allow the validations to be set via mass-assignment. This does introduce an extra @@ -114,5 +148,6 @@ [DockYard](http://dockyard.com), LLC &copy; 2013 [@dockyard](http://twitter.com/dockyard) [Licensed under the MIT license](http://www.opensource.org/licenses/mit-license.php) +