Isnor Creative
Isnor Creative Blog
Ruby, Ruby on Rails, Ember, Elm, Phoenix, Elixir, React, Vue

Jun 10, 2014

Rapscallion - Ruby on Rails Client Side Validations Gem

Add this line to application.js:

//= require rapscallion/validations

Activate with Javascript:

$('.validate_me').rapscallion();

Options:

  • Change class of error message div
    errormessagecontainerclass: “errormessages”

  • Set a class on field with error
    fieldwitherrorclass: ‘haserror’

  • Set a class on field with success
    fieldvalidclass: ‘is_valid’

  • Container for input – used to add and remove error messages
    field_container: ‘div.input’

  • Event that triggers validation
    trigger: ‘blur’

eg $(‘.rapscallion’).rapscallion({errormessagecontainerclass: ‘errors’, fieldcontainer: ‘.field’})

Add this line to Gemfile:

gem 'rapscallion'

Input example with Simple Form:

.input
  = f.input :username, input_html: {class: 'rapscallion'}

Modify form tag when validating an existing record (for example to avoid uniqueness validation problems):

= simple_form_for @thing, html: {data: {existing_record: @thing.id}} do |f|

Add validations in model as you normally would:

class User < ActiveRecord::Base
    validate :username, presence: true
end

http://www.github.com/gordonbisnor/rapscallion

Gordon B. Isnor

Gordon B. Isnor writes about Ruby on Rails, Ember.js, Elm, Elixir, Phoenix, React, Vue and the web.
If you enjoyed this article, you may be interested in the occasional newsletter.

I am now available for project work. I have availability to build greenfield sites and applications, to maintain and update/upgrade existing applications, team augmentation. I offer website/web application assessment packages that can help with SEO/security/performance/accessibility and best practices. Let’s talk

comments powered by Disqus