0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
ca-validation is validation for rails
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

~> 5.2.3
 Project Readme

Ca::Validation

Wrap the dry-validation for rails

Usage

First you should define a validator class.

class AddBookValidator
  include Ca::Validation

  validate do
    required(:book).schema do
      required(:title).filled(:str?)
      required(:author_name).filled(:str?)
    end
  end
end

Then you can use valid?

def create
  if params.valid?(AddBookValidator)
    book = Book.create(params.result[:book])
    redirect_to book
  else
    render :new
  end
end
<% if params.errors.any? %>
  <div id="error_explanation">
    <h2><%= pluralize(params.errors[:book].count, "error") %> prohibited this book from being saved:</h2>

    <ul>
    <% params.errors(full: true)[:book].each do |k, message| %>
      <li><%= message.first %></li>
    <% end %>
    </ul>
  </div>
<% end %>

You can reference https://dry-rb.org/gems/dry-validation/comparison-with-activemodel/

Installation

Add this line to your application's Gemfile:

gem 'ca-validation'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ca-validation

Contributing

Contribution directions go here.

License

The gem is available as open source under the terms of the MIT License.