Tableless validation in Rails 4.2 -


i trying validate form, not bound real model, did following:

a model

class formrequest      include activemodel::model      attr_accessor :email      validates :email, presence: true, email: true  end 

and method in controller

# form shown def index     @form_request = formrequest.new end 

but when load page error:

unknown validator: 'emailvalidator'

what did miss?

you don't have email: true validator.

to validate email can use regular expression:

valid_email = /\a[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i validates :email, presence: true, format: { with: valid_email } 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -