Do not call the model layer directly from the view.
Do not construct complex formats in the view, and output them to a method or model of the view helper.
Use partial templates and layouts to reduce duplicate code.
Join the client side validation to the usual validators. The steps to do are:
Declares a custom validator from Clientsidevalidations::middleware::base.
Module Clientsidevalidations::middleware
class Email < Base
def response
if request.params[:email] =~/ ^ ([^@\s]+) @ ((?: [-a-z0-9]+\.) +[a-z]{2,}) $/i
self.status =/
else
self.status = 404
End
Super
end End
Create a new file Public/javascripts/rails.validations.custom.js.coffee and add a reference to it in your Application.js.coffee file:
# App/assets/javascripts/application.js.coffee
#= require Rails.validations.custom
Add your client validator:
#public/javascripts/rails.validations.custom.js.coffee
clientsidevalidations.validators.remote[' email '] = ( element, options)->
if $.ajax ({
URL: '/validators/email.json ',
data: {email:element.val ()},
Async:false
}). status = = 404 return
options.message | | ' Invalid e-mail format '