{"id":213077,"date":"2014-02-18T21:46:03","date_gmt":"2014-02-18T17:46:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=213077"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=213077","title":{"rendered":"<span class=\"post_title\">Rails: Frontend-\u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0432 \u0441\u0442\u0438\u043b\u0435 DRY<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u041a\u043e\u0433\u0434\u0430 \u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u043b \u0437\u0430\u0434\u0443\u043c\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043e \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438\u043e\u0431\u0449\u0438\u0442\u044c\u0441\u044f \u043a \u043c\u0438\u0440\u0443 \u0432\u0435\u0431-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438, \u0438 \u0432\u044b\u0431\u0438\u0440\u0430\u043b \u044f\u0437\u044b\u043a, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0430\u0447\u043d\u0443, \u043e\u0434\u043d\u0430 \u0438\u0437 \u0432\u0438\u043a\u0438\u043f\u0435\u0434\u0438\u0439 \u043c\u043d\u0435 \u043d\u0430\u043f\u0435\u043b\u0430, \u0447\u0442\u043e \u0432 \u043e\u0441\u043d\u043e\u0432\u0435 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u0438\u0438 Rails \u043b\u0435\u0436\u0430\u0442 2 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430: <b>Convention over configuration (CoC)<\/b> \u0438 <b>Don\u2019t Repeat Yourself (DRY)<\/b>. \u0427\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u2014 \u044f \u0442\u043e\u0433\u0434\u0430 \u0432\u043e\u0431\u0449\u0435 \u043d\u0435 \u043f\u043e\u043d\u044f\u043b \u043e \u0447\u0451\u043c \u0440\u0435\u0447\u044c, \u0430 \u0432\u043e\u0442 \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u043e\u043d\u044f\u043b, \u043f\u0440\u0438\u043d\u044f\u043b \u0438 \u043e\u0436\u0438\u0434\u0430\u043b, \u0447\u0442\u043e \u0432 \u043d\u0435\u0434\u0440\u0430\u0445 \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430, \u044f \u043e\u0442\u044b\u0449\u0443 \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u043c\u043d\u0435 \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u043c\u043e\u0434\u0435\u043b\u0438, \u0438 \u043f\u043e\u0442\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043a\u0430\u043a \u0434\u043b\u044f front, \u0442\u0430\u043a \u0438 \u0434\u043b\u044f back \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u041a\u0430\u043a \u0432\u044b\u044f\u0441\u043d\u0438\u043b\u043e\u0441\u044c \u043f\u043e\u0437\u0436\u0435 \u2014 \u043c\u0435\u043d\u044f \u0436\u0434\u0430\u043b\u043e \u0440\u0430\u0437\u043e\u0447\u0430\u0440\u043e\u0432\u0430\u043d\u0438\u0435. \u0412 \u0440\u0435\u043b\u044c\u0441\u0430\u0445 \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0439 \u0448\u0442\u0443\u043a\u0438 \u043d\u0435\u0442, \u0438 \u0432\u0441\u0451, \u0447\u0442\u043e \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043e\u0442\u044b\u0441\u043a\u0430\u0442\u044c \u043f\u043e \u0442\u0435\u043c\u0435 \u0432 \u0445\u043e\u0434\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u2014 \u044d\u0442\u043e railscast \u043f\u0440\u043e <i>client_side_validations gem<\/i>.<\/p>\n<p>  \u042f \u0442\u043e\u0433\u0434\u0430 \u043e javascript \u0437\u043d\u0430\u043b \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e, \u0447\u0442\u043e \u043e\u043d \u0435\u0441\u0442\u044c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043c\u043e\u043b\u0447\u0430 \u043f\u0440\u0438\u043a\u0440\u0443\u0442\u0438\u0442\u044c \u0433\u0435\u043c \u043a \u0440\u043e\u0436\u0434\u0430\u044e\u0449\u0435\u043c\u0443\u0441\u044f \u0431\u043b\u043e\u0433\u0443 \u0438 \u043e\u0442\u043b\u043e\u0436\u0438\u0442\u044c \u0442\u0435\u043c\u0443 dry-\u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0439 \u0434\u043e \u0431\u043e\u043b\u0435\u0435 \u0431\u043b\u0438\u0437\u043a\u043e\u0433\u043e \u0437\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u0430 \u0441 js. \u0418 \u0432\u043e\u0442 \u044d\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u0438\u0448\u043b\u043e: \u043c\u043d\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u043b\u0441\u044f \u0433\u0438\u0431\u043a\u0438\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0444\u043e\u0440\u043c, \u0438 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 <code>validates_inclusion_of<\/code> \u043d\u0430 js-\u043c\u0430\u043d\u0435\u0440 \u044f \u0431\u044b\u043b \u043d\u0435 \u043d\u0430\u043c\u0435\u0440\u0435\u043d. \u0414\u0430 \u0438 \u0433\u0435\u043c \u0442\u043e\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f.<\/p>\n<h4>\u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438<\/h4>\n<p>  \u041d\u0430\u0439\u0442\u0438 \u0441\u043f\u043e\u0441\u043e\u0431, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442:  <\/p>\n<ol>\n<li>\u043f\u0440\u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0434\u043d\u0443 \u043b\u043e\u0433\u0438\u043a\u0443: \u043a\u0430\u043a \u0434\u043b\u044f \u0431\u044d\u043a\u0430, \u0442\u0430\u043a \u0438 \u0434\u043b\u044f \u0444\u0440\u043e\u043d\u0442\u0430<\/li>\n<li>\u0431\u044b\u0441\u0442\u0440\u043e \u00ab\u0432\u0435\u0448\u0430\u0442\u044c\u00bb \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0435 \u0444\u043e\u0440\u043c\u044b \u0438 \u0433\u0438\u0431\u043a\u043e \u0438\u0445 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c (\u043a\u0430\u043a \u043b\u043e\u0433\u0438\u043a\u0443, \u0442\u0430\u043a \u0438 \u0432\u0438\u0437\u0443\u0430\u043b)<\/li>\n<\/ol>\n<p>  \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u0432 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0434\u0435\u043c\u043a\u0435: <a href=\"http:\/\/sandbox.alexfedoseev.com\/dry-validation\/showoff\">http:\/\/sandbox.alexfedoseev.com\/dry-validation\/showoff<\/a><\/p>\n<p>  \u0418 \u043f\u0430\u0440\u0430 \u043f\u043e\u044f\u0441\u043d\u044f\u044e\u0449\u0438\u0445 \u0430\u0431\u0437\u0430\u0446\u0435\u0432 \u043d\u0438\u0436\u0435.<\/p>\n<h4>\u0418\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b<\/h4>\n<p>  \u0417\u0430\u0431\u044b\u043b \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044c, \u0447\u0442\u043e \u044f \u0432 \u043c\u0435\u0440\u0443 \u043b\u0435\u043d\u0438\u0432, \u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 js-\u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440 \u0432 \u043c\u043e\u0438 \u043f\u043b\u0430\u043d\u044b \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u043d\u0435 \u0432\u0445\u043e\u0434\u0438\u043b\u043e. \u0418\u0437 \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043c\u043e\u0439 \u0432\u044b\u0431\u043e\u0440 \u043f\u0430\u043b \u043d\u0430 <a href=\"http:\/\/jqueryvalidation.org\/\"><b>jQuery Validation Plugin<\/b><\/a>.<\/p>\n<p>  \u0415\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043a\u0438\u043d\u0443\u0442\u044c \u0432 js-\u0430\u0441\u0441\u0435\u0442\u044b \u0438\u043b\u0438 <a href=\"https:\/\/github.com\/danryan\/jquery-validation-rails\">\u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u0430\u043a \u0433\u0435\u043c<\/a>. <br \/>  \u0411\u043e\u043b\u044c\u0448\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u0433\u043e \u043d\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f.<\/p>\n<p>  \u041d\u0435\u0441\u0442\u0438 \u0434\u043e\u0431\u0440\u043e\u0435 \u0441\u0432\u0435\u0442\u043b\u043e\u0435 \u0431\u0443\u0434\u0443 \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u0438\u043c\u0435\u0440. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u0430\u0434\u0440\u0435\u0441\u0430 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0430\u0434\u0440\u0435\u0441\u0430 (\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u0432 \u043d\u0435\u0434\u0435\u043b\u044e \u043f\u0443\u043b\u044f\u0435\u043c \u043f\u0438\u0441\u044c\u043c\u043e).<\/p>\n<h4>\u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0441\u0443\u0442\u0438<\/h4>\n<p>  \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0435\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u2014 <code>Email<\/code><br \/>  \u0418 \u0434\u0432\u0430 \u0435\u0451 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430:  <\/p>\n<ul>\n<li><code>email<\/code> \u2014 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0439 \u0430\u0434\u0440\u0435\u0441<\/li>\n<li><code>frequency<\/code> \u2014 \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u043d\u043e\u0441\u0442\u044c, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0443\u0445\u043e\u0434\u0438\u0442\u044c \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u0430\u0434\u0440\u0435\u0441<\/li>\n<\/ul>\n<p>  \u041a\u0430\u043a\u0438\u0435 \u0431\u0443\u0434\u0443\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f:  <\/p>\n<ul>\n<li>\u043d\u0430\u043b\u0438\u0447\u0438\u0435 <code>email<\/code> \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e<\/li>\n<li><code>email<\/code> \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u0435\u043d<\/li>\n<li><code>email<\/code> \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c email (\u0441 \u0441\u043e\u0431\u0430\u043a\u043e\u0439 \u0438 \u043f\u0440\u043e\u0447\u0438\u043c\u0438 \u0440\u044e\u0448\u0435\u0447\u043a\u0430\u043c\u0438)<\/li>\n<li><code>frequency<\/code> \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u0435\u043d, \u043d\u043e \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c, \u0442\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 <b>\u043e\u0442 1 \u0434\u043e 7<\/b><\/li>\n<\/ul>\n<p>  \u0412\u043e\u043f\u043b\u043e\u0449\u0430\u0435\u043c:<\/p>\n<p>  <b>app\/models\/email.rb<\/b><\/p>\n<pre><code class=\"ruby\">class Email &lt; ActiveRecord::Base    before_save { self.email = email.downcase }    VALID_EMAIL_REGEX = \/\\A[\\w+\\-.]+@[a-z\\d\\-.]+\\.[a-z]+\\z\/i   validates :email, presence: true,             uniqueness: { case_sensitive: false },             format: { with: VALID_EMAIL_REGEX }   validates_inclusion_of :frequency, in: 1..7, allow_blank: true  end <\/code><\/pre>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 \u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0432\u0441\u0451 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e<\/b><\/p>\n<div class=\"spoiler_text\"><b>app\/controllers\/emails_controller.rb<\/b><\/p>\n<pre><code class=\"ruby\">class EmailsController &lt; ApplicationController    def new     @email = Email.new   end    def create     @email = Email.new(email_params)     if @email.save       flash[:success] = 'Email \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d!'       redirect_to emails_url     else       render :new     end   end    private      def email_params       params.require(:email).permit(:email, :frequency)     end  end <\/code><\/pre>\n<p>  <b>app\/views\/emails\/new.html.haml<\/b><\/p>\n<pre><code class=\"ruby\">%h1 \u041d\u043e\u0432\u0430\u044f \u043f\u043e\u0447\u0442\u0430 = form_for @email do |f|    = render partial: 'shared\/error_messages', locals: { object: f.object }    %p= f.text_field :email, placeholder: '\u041f\u043e\u0447\u0442\u0430'   %p= f.text_field :frequency, placeholder: '\u041f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0438'   %p= f.submit '\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c!' <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0448\u0430\u0433 \u2014 \u043f\u043e\u0432\u0435\u0441\u0438\u0442\u044c \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440 \u043d\u0430 \u0444\u043e\u0440\u043c\u0443 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0447\u0442\u043e \u043a \u0447\u0435\u043c\u0443.<br \/>  \u0414\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e: <code>$('#form').validate();<\/code>  <\/p>\n<blockquote><p>\u041f\u043e\u0432\u0442\u043e\u0440\u044e <a href=\"http:\/\/jqueryvalidation.org\/documentation\/\">\u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u043a \u043f\u043b\u0430\u0433\u0438\u043d\u0443<\/a>, \u0447\u0442\u043e\u0431\u044b \u043a \u043d\u0435\u0439 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f. \u0422\u0430\u043c \u0441\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0441\u0442\u044c\u044e \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u043d\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0432\u0441\u044f \u0435\u0441\u0442\u044c.<\/p><\/blockquote>\n<p>  \u0418\u0442\u0430\u043a, \u0432\u0435\u0448\u0430\u0435\u043c:<\/p>\n<p>  <b>app\/assets\/javascripts\/emails.js.coffee<\/b><\/p>\n<pre><code class=\"coffeescript\">jQuery -&gt;   validate_url = '\/emails\/validate'    $('#new_email, [id^=edit_email_]').validate(     debug: true     rules:       'email[email]':         required: true         remote:           url: validate_url           type: 'post'       'email[frequency]':         remote:           url: validate_url           type: 'post'   ) <\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0439\u0434\u0435\u043c\u0441\u044f \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u0435:  <\/p>\n<ul>\n<li><code>validate_url = '\/emails\/validate'<\/code><br \/>  \u0430\u0434\u0440\u0435\u0441, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c ajax-\u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u043e\u043b\u0435\u0439<\/li>\n<li><code>$('#new_email, [id^=edit_email_]').validate<\/code> <br \/>  \u0432\u0435\u0448\u0430\u0435\u043c \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440 \u043a\u0430\u043a \u043d\u0430 \u0444\u043e\u0440\u043c\u0443 \u043d\u043e\u0432\u043e\u0433\u043e email, \u0442\u0430\u043a \u0438 \u043d\u0430 \u0444\u043e\u0440\u043c\u0443 \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0430\u0434\u0440\u0435\u0441\u043e\u0432<\/li>\n<li><code>debug: true<\/code> <br \/>  \u043c\u0435\u0442\u043e\u0434 \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0443 \u0444\u043e\u0440\u043c\u044b, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0440\u0430\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c\u0441\u044f \u0441 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u043c\u0438<\/li>\n<li><code>rules:<\/code> <br \/>  \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0434\u043b\u044f \u043f\u043e\u043b\u0435\u0439, \u0443 \u043f\u043b\u0430\u0433\u0438\u043d\u0430 \u0438\u0445 \u043c\u043d\u043e\u0433\u043e \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438 (\u0441\u043c. \u0434\u043e\u043a\u0438), \u043d\u043e \u043d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0442 \u043f\u043e\u043a\u0430 \u0442\u043e\u043b\u044c\u043a\u043e 2<\/li>\n<li><code>'email[email]':<\/code> <br \/>  name\u2013\u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u043f\u043e\u043b\u044f \u0444\u043e\u0440\u043c\u044b (\u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0438\u043c\u0435\u043d\u0430 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0431\u0435\u0437 \u043a\u0430\u0432\u044b\u0447\u0435\u043a, \u0441\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u0430\u043c\u0438 \u2014 \u0431\u0435\u0440\u0451\u043c \u0432 \u043a\u0430\u0432\u044b\u0447\u043a\u0438)<\/li>\n<\/ul>\n<p>  \u041d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0434\u0432\u0443\u0445 \u043c\u0435\u0442\u043e\u0434\u0430\u0445 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c\u0441\u044f \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435.<\/p>\n<h5>remote<\/h5>\n<p>  <\/p>\n<pre><code class=\"coffeescript\">remote:   url: validate_url   type: 'post' <\/code><\/pre>\n<p>  \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0433\u043b\u0430\u0432\u043d\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430 \u2014 <code>remote<\/code>. \u0421 \u0435\u0433\u043e \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0442\u0441\u044b\u043b\u0430\u0442\u044c ajax-\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u0441\u0435\u0440\u0432\u0435\u0440\u0443 \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<p>  \u041a\u0430\u043a \u043e\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442: \u043c\u0435\u0442\u043e\u0434\u0443 \u043d\u0443\u0436\u043d\u043e \u0441\u043a\u043e\u0440\u043c\u0438\u0442\u044c url \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u0435\u0433\u043e \u0442\u0438\u043f (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0442\u0441\u044b\u043b\u0430\u0435\u043c post-\u0437\u0430\u043f\u0440\u043e\u0441). \u042d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f \u043d\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0443.<\/p>\n<p>  \u0412 \u043e\u0442\u0432\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c <code>json<\/code>:  <\/p>\n<ul>\n<li>\u043e\u0442\u0432\u0435\u0442 <code>true<\/code> \u2014 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0441 \u043f\u043e\u043b\u0435\u043c \u0432\u0441\u0451 \u043e\u043a<\/li>\n<li>\u043e\u0442\u0432\u0435\u0442\u044b <code>false<\/code>, <code>undefined<\/code> \u0438\u043b\u0438 <code>null<\/code>, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043b\u044e\u0431\u0430\u044f \u0434\u0440\u0443\u0433\u0430\u044f <code>string'\u0430<\/code> \u2014 \u0440\u0430\u0441\u0446\u0435\u043d\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u043a\u0430\u043a \u0441\u0438\u0433\u043d\u0430\u043b \u043f\u0440\u043e\u0432\u0430\u043b\u044c\u043d\u043e\u0439 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438<\/li>\n<\/ul>\n<h5>required<\/h5>\n<p>  <\/p>\n<pre><code class=\"coffeescript\">required: true <\/code><\/pre>\n<p>  \u041c\u0435\u0442\u043e\u0434 \u00ab\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u043b\u0435\u0439\u00bb. \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0435\u043b\u044c\u0437\u044f (\u0434\u0430 \u0438 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e) \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u0441\u0435\u0440\u0432\u0435\u0440\u0443, \u2014 \u044d\u0442\u043e <code>validates_presence_of<\/code> (\u0442\u043e \u0435\u0441\u0442\u044c \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u043d\u0430\u043b\u0438\u0447\u0438\u044f). \u042d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440\u0430 \u2014 \u043e\u043d \u0434\u0451\u0440\u0433\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 <code>remote<\/code> \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0432 \u043f\u043e\u043b\u0435 \u0432\u0432\u043e\u0434\u0438\u043b\u0438\u0441\u044c \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u0434\u0430\u043d\u043d\u044b\u0435. \u00ab\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0440\u0443\u043a\u0430\u043c\u0438\u00bb \u0434\u0430\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u044f \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0447\u0435\u0440\u0435\u0437 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434. \u041a\u0441\u0442\u0430\u0442\u0438, \u043e\u043d \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043c\u043e\u0436\u043d\u043e (\u0438 \u043d\u0443\u0436\u043d\u043e) \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0433\u043e.<\/p>\n<h4>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c<\/h4>\n<p>  \u0412\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440 \u043f\u043e\u0432\u0435\u0448\u0435\u043d, ajax-\u0437\u0430\u043f\u0440\u043e\u0441 \u0443\u0445\u043e\u0434\u0438\u0442 \u043a \u0441\u0435\u0440\u0432\u0435\u0440\u0443, \u0447\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435:  <\/p>\n<ul>\n<li>\u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441<\/li>\n<li>\u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0440\u043e\u0443\u0442 \u043a \u044d\u0442\u043e\u043c\u0443 \u043c\u0435\u0442\u043e\u0434\u0443<\/li>\n<\/ul>\n<p>  <b>app\/controllers\/emails_controller.rb<\/b><\/p>\n<pre><code class=\"ruby\">  def validate     # \u043f\u043e\u043a\u0430 \u043f\u0443\u0441\u0442\u043e\u0439   end <\/code><\/pre>\n<p>  <b>config\/routes.rb<\/b><\/p>\n<pre><code class=\"ruby\">resources :emails post 'emails\/validate', to: 'emails#validate', as: :emails_validation <\/code><\/pre>\n<p>  \u041e\u0442\u043b\u0438\u0447\u043d\u043e, \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u0435\u0440\u0432\u0435\u0440 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c post-\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430 \u0430\u0434\u0440\u0435\u0441 <code>'\/emails\/validate'<\/code><br \/>  \u0414\u0430\u0432\u0430\u0442\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0441\u0435\u0440\u0432\u0435\u0440, \u043e\u0442\u043a\u0440\u043e\u0435\u043c \u0444\u043e\u0440\u043c\u0443 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f <code>Email<\/code> \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435 (lvh.me:3000\/emails\/new), \u043d\u0430\u0431\u0435\u0440\u0451\u043c \u00ab\u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c\u00bb \u0432 \u043f\u043e\u043b\u0435 \u0444\u043e\u0440\u043c\u044b \u0438 \u0431\u0435\u0433\u043e\u043c \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u2014 \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0447\u0442\u043e \u0436\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442 \u043d\u0430\u043c \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440.<\/p>\n<p>  \u0412 \u043e\u0431\u0449\u0435\u043c-\u0442\u043e, \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043e\u0436\u0438\u0434\u0430\u0442\u044c:<\/p>\n<pre><code class=\"bash\">Started POST &quot;\/emails\/validate&quot; for 127.0.0.1 at 2014-02-17 22:10:31 +0000 Processing by EmailsController#validate as JSON   Parameters: {&quot;email&quot;=&gt;{&quot;frequency&quot;=&gt;&quot;\u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c&quot;}} <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043e \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438: \u0447\u0442\u043e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u044d\u0442\u0438\u043c \u0434\u043e\u0431\u0440\u043e\u043c \u2014 \u043a\u0430\u043a \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0438 \u0447\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c:  <\/p>\n<ul>\n<li>\u0438\u0437 \u043f\u0440\u0438\u043b\u0435\u0442\u0435\u0432\u0448\u0435\u0433\u043e \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 <code>json<\/code>, \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 <code>Email<\/code><\/li>\n<li>\u0438 \u0434\u0451\u0440\u043d\u0435\u043c \u0435\u0433\u043e \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u0447\u0435\u0440\u0435\u0437 <code>ActiveModel<\/code><\/li>\n<li>\u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0430\u0440\u0438\u0441\u0443\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 <code>ActiveModel::Errors<\/code> (\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0439 \u0447\u0435\u0440\u0435\u0437 \u043c\u0435\u0442\u043e\u0434 <code>errors<\/code>), \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0445\u044d\u0448 <code>@messages<\/code> \u2014 \u043b\u0438\u0431\u043e \u0441 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438 (\u0435\u0441\u043b\u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u043d\u0435 \u043f\u0440\u043e\u0448\u043b\u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e), \u043b\u0438\u0431\u043e \u043f\u0443\u0441\u0442\u043e\u0439 (\u0435\u0441\u043b\u0438 \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c \u0432\u0441\u0451 \u0445\u043e\u0440\u043e\u0448\u043e)<\/li>\n<li>\u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u044d\u0442\u043e\u0442 \u0445\u044d\u0448 \u0438, \u0435\u0441\u043b\u0438 \u043e\u043d \u043f\u0443\u0441\u0442\u043e\u0439 \u2014 \u043e\u0442\u0432\u0435\u0442\u0438\u043c \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0443 <code>true<\/code>, \u0430 \u0435\u0441\u043b\u0438 \u0432 \u043d\u0451\u043c \u0435\u0441\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c\u043e\u0433\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u2014 \u043e\u0442\u0432\u0435\u0442\u0438\u043c \u0442\u0435\u043a\u0441\u0442\u043e\u043c \u044d\u0442\u0438\u0445 \u043e\u0448\u0438\u0431\u043e\u043a, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0446\u0435\u043d\u0435\u043d\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c \u043a\u0430\u043a \u043f\u0440\u043e\u0432\u0430\u043b\u044c\u043d\u0430\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f. \u0418, \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u043f\u043b\u0430\u0433\u0438\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u0438\u043d\u0433\u0443 \u043a\u0430\u043a \u0442\u0435\u043a\u0441\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435.<\/li>\n<\/ul>\n<p>  \u0428\u043e-\u043a\u043e-\u043b\u0430\u0434! \u041c\u0430\u043b\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432 \u043c\u043e\u0434\u0435\u043b\u0435, \u0442\u0430\u043a \u0435\u0449\u0451 \u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432 \u043b\u043e\u043a\u0430\u043b\u0435 \u0440\u0435\u043b\u044c\u0441.<\/p>\n<p>  \u041a\u0441\u0442\u0430\u0442\u0438, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0438\u0445 \u043d\u0430\u043f\u0438\u0448\u0435\u043c.<\/p>\n<p>  <b>config\/locales\/ru.yml<\/b><\/p>\n<pre><code class=\"ruby\">ru:   activerecord:     attributes:       email:         email: &quot;\u041f\u043e\u0447\u0442\u0430&quot;         frequency: &quot;\u041f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u043d\u043e\u0441\u0442\u044c&quot;     errors:       models:         email:           attributes:             email:               blank: &quot;\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u0430&quot;               taken: &quot;\u0443\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0438&quot;               invalid: &quot;\u0438\u043c\u0435\u0435\u0442 \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442&quot;             frequency:               inclusion: &quot;\u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 \u043e\u0442 1 \u0434\u043e 7 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e&quot; <\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u041e I18n \u0447\u0438\u0442\u0430\u0435\u043c \u0432 \u0433\u0430\u0439\u0434\u0430\u0445 Rails: <a href=\"http:\/\/guides.rubyonrails.org\/i18n.html\">http:\/\/guides.rubyonrails.org\/i18n.html<\/a><\/p><\/blockquote>\n<p>  \u041d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u043d\u044b.<br \/>  \u0422\u0435\u043f\u0435\u0440\u044c \u0441\u0430\u043c\u043e\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435 \u2014 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u043e\u0442\u0432\u0435\u0442 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0443.<\/p>\n<p>  \u0421\u0440\u0430\u0437\u0443 \u0432\u044b\u0432\u0430\u043b\u0438\u0432\u0430\u044e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c \u043f\u043e \u0441\u0442\u0440\u043e\u0447\u043a\u0430\u043c:<\/p>\n<p>  <b>app\/controllers\/emails_controller.rb<\/b><\/p>\n<pre><code class=\"ruby\">def validate   email = Email.new(email_params)   email.valid?    field = params[:email].first[0]   @errors = email.errors[field]    if @errors.empty?     @errors = true   else     name = t(&quot;activerecord.attributes.email.#{field}&quot;)     @errors.map! { |e| &quot;#{name} #{e}&lt;br \/&gt;&quot; }   end    respond_to do |format|     format.json { render json: @errors }   end end <\/code><\/pre>\n<p>  \u041f\u043e\u0435\u0445\u0430\u043b\u0438.<\/p>\n<pre><code class=\"ruby\">email = Email.new(email_params) email.valid? <\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u0437 \u043f\u0440\u0438\u043b\u0435\u0442\u0435\u0432\u0448\u0438\u0445 \u043e\u0442 \u0444\u043e\u0440\u043c\u044b \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0438 \u0434\u0451\u0440\u0433\u0430\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043d\u0430 \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0441\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 <code>ActiveModel::Errors<\/code>. \u0412 \u0445\u044d\u0448\u0435 <code>@messages<\/code> \u0441 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438, \u043f\u043e\u043c\u0438\u043c\u043e \u043d\u0443\u0436\u043d\u044b\u0445 \u043d\u0430\u043c \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c\u043e\u0433\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430, \u0431\u0443\u0434\u0443\u0442 \u043b\u0435\u0436\u0430\u0442\u044c \u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 (\u0442.\u043a. \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u2014 <code>nil<\/code>, \u043f\u0440\u0438\u043b\u0435\u0442\u0435\u043b\u043e \u0436\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c\u043e\u0433\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430). <\/p>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043e\u0431\u044a\u0435\u043a\u0442, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u043a\u0430\u043a \u0435\u0433\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c:<\/p>\n<pre><code class=\"ruby\">(rdb:938) email.errors #=&gt; #&lt;ActiveModel::Errors:0x007fbbe378dfb0 @base=#&lt;Email id: nil, email: nil, frequency: &quot;\u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c&quot;, created_at: nil, updated_at: nil&gt;, @messages={:email=&gt;[&quot;\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u0430&quot;, &quot;\u0438\u043c\u0435\u0435\u0442 \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442&quot;], :frequency=&gt;[&quot;\u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 \u043e\u0442 1 \u0434\u043e 7 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e&quot;]}&gt; <\/code><\/pre>\n<p>  \u041c\u044b \u0432\u0438\u0434\u0438\u043c \u0445\u044d\u0448 \u0441 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445, \u0438 \u0434\u043e\u043a\u0438 \u043d\u0430\u043c <a href=\"http:\/\/api.rubyonrails.org\/classes\/ActiveModel\/Errors.html#method-i-5B-5D\">\u043f\u043e\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043a\u0430\u043a \u0438\u0445 \u0434\u043e\u0441\u0442\u0430\u0442\u044c<\/a>:<\/p>\n<pre><code class=\"ruby\">(rdb:938) email.errors['frequency'] #=&gt; [&quot;\u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 \u043e\u0442 1 \u0434\u043e 7 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e&quot;] <\/code><\/pre>\n<p>  \u0422\u043e \u0435\u0441\u0442\u044c \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0434\u043e\u0441\u0442\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u0434\u043b\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430, \u043d\u0430\u043c \u043f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u044c \u0438\u043c\u044f \u044d\u0442\u043e\u0433\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430. <br \/>  \u042d\u0442\u043e \u043c\u044b \u0432\u044b\u0442\u044f\u043d\u0435\u043c \u0438\u0437 \u0445\u044d\u0448\u0430 <code>params<\/code>:<\/p>\n<pre><code class=\"ruby\"># \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0445\u044d\u0448 (rdb:938) params #=&gt; {&quot;email&quot;=&gt;{&quot;frequency&quot;=&gt;&quot;\u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c&quot;}, &quot;controller&quot;=&gt;&quot;emails&quot;, &quot;action&quot;=&gt;&quot;validate&quot;}  # \u043d\u0430\u043c \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043e\u0441\u0442\u0430\u0451\u043c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b (rdb:938) params[:email] #=&gt; {&quot;frequency&quot;=&gt;&quot;\u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c&quot;}  # \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0437\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 \u0443\u043b\u0435\u0442\u0430\u0435\u0442 \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u0434\u0438\u043d \u0430\u0442\u0440\u0438\u0431\u0443\u0442, \u0442\u043e \u0437\u0430\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u0435\u0440\u0432\u044b\u0439 (rdb:938) params[:email].first #=&gt; [&quot;frequency&quot;, &quot;\u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c&quot;]  # \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u043a\u043b\u044e\u0447, \u0442\u043e \u0435\u0441\u0442\u044c \u0438\u043c\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 -&gt; \u0437\u0430\u0431\u0438\u0440\u0430\u0435\u043c (rdb:938) params[:email].first[0] #=&gt; &quot;frequency&quot; <\/code><\/pre>\n<p>  \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435:<\/p>\n<pre><code class=\"ruby\">field = params[:email].first[0] @errors = email.errors[field] <\/code><\/pre>\n<p>  \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0434\u043e\u0441\u0442\u0430\u043b\u0438 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c\u043e\u0433\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u043c\u043e\u0434\u0435\u043b\u0438, \u043f\u043e\u0442\u043e\u043c \u0432\u044b\u0442\u0430\u0449\u0438\u043b\u0438 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445.<\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u043e\u0442\u0432\u0435\u0442 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0443:<\/p>\n<pre><code class=\"ruby\">if @errors.empty?   @errors = true else   name = t(&quot;activerecord.attributes.email.#{field}&quot;)   @errors.map! { |e| &quot;#{name} #{e}&lt;br \/&gt;&quot; } end <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438 \u043f\u0443\u0441\u0442, \u0442\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <code>@errors<\/code> \u2014 \u044d\u0442\u043e <code>true<\/code> (\u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e\u0442 \u043e\u0442\u0432\u0435\u0442 \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u043f\u043b\u0430\u0433\u0438\u043d, \u0435\u0441\u043b\u0438 \u043e\u0448\u0438\u0431\u043e\u043a \u043d\u0435\u0442).<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0436\u0435 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 \u0435\u0441\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438, \u0442\u043e:  <\/p>\n<ul>\n<li>\u0435\u0441\u043b\u0438 \u043c\u044b \u043e\u0442\u0434\u0430\u0434\u0438\u043c \u0435\u0433\u043e \u043a\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e <code>@errors<\/code>, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 <b>\u00ab\u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 \u043e\u0442 1 \u0434\u043e 7 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u00bb<\/b> (\u0430 \u0435\u0441\u043b\u0438 \u0438\u0445 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e, \u0442\u043e \u043e\u043d\u0438 \u0432\u043e\u0431\u0449\u0435 \u00ab\u0441\u043b\u0438\u043f\u043d\u0443\u0442\u0441\u044f\u00bb \u043f\u0440\u0438 \u0432\u044b\u0432\u043e\u0434\u0435)<\/li>\n<\/ul>\n<p>  \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b:  <\/p>\n<ul>\n<li>\u0432\u044b\u0442\u0430\u0441\u043a\u0438\u0432\u0430\u0435\u043c \u0438\u043c\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 \u043b\u043e\u043a\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0435\u043b\u044c\u0441:<br \/>  <code>name = t(&quot;activerecord.attributes.email.#{field}&quot;)<\/code><\/li>\n<li>\u0438 \u0432 \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0441 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u044d\u0442\u043e \u0438\u043c\u044f \u0432 \u043d\u0430\u0447\u0430\u043b\u043e \u0441 \u043f\u0440\u043e\u0431\u0435\u043b\u043e\u043c:<br \/>  <code>@errors.map! { |e| &quot;#{name} #{e}&lt;br \/&gt;&quot; }<\/code><\/li>\n<li>\u043c\u043e\u0436\u043d\u043e \u0435\u0449\u0451 \u0438 <code>br<\/code> \u0432 \u043a\u043e\u043d\u0446\u0435 \u043a\u0430\u0436\u0434\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0440\u0438\u043b\u0435\u043f\u0438\u0442\u044c, \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0432\u0451\u0440\u0441\u0442\u043a\u0438, \u043a\u043e\u0440\u043e\u0447\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043f\u043e \u0432\u043a\u0443\u0441\u0443<\/li>\n<\/ul>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432 \u0438\u0442\u043e\u0433\u0435 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435: <br \/>  <b>\u00ab\u041f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u043d\u043e\u0441\u0442\u044c \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 \u043e\u0442 1 \u0434\u043e 7 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u00bb<\/b>.<\/p>\n<p>  \u0418 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0448\u0442\u0440\u0438\u0445 \u2014 \u043f\u0430\u043a\u0443\u0435\u043c \u0432\u0441\u0451 \u044d\u0442\u043e \u0432 <code>json<\/code>:<\/p>\n<pre><code class=\"ruby\">respond_to do |format|   format.json { render json: @errors } end <\/code><\/pre>\n<p>  Rails \u043e\u0442\u0434\u0430\u0451\u0442 \u043e\u0442\u0432\u0435\u0442 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0443.<\/p>\n<h4>\u0420\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043c<\/h4>\n<p>  \u0414\u043b\u044f \u043e\u0434\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u043e \u0443 \u043d\u0430\u0441 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0431\u0443\u0434\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u043c\u043e\u0434\u0435\u043b\u0435\u0439. \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0435-\u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0442\u044c-\u0441\u0435\u0431\u044f, \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0440\u043e\u0443\u0442\u0438\u043d\u0433 \u0438 \u043c\u0435\u0442\u043e\u0434 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435.<\/p>\n<h5>\u0420\u043e\u0443\u0442\u0438\u043d\u0433<\/h5>\n<p>  <b>config\/routes.rb<\/b><\/p>\n<pre><code class=\"ruby\"># \u0431\u044b\u043b\u043e post 'emails\/validate', to: 'emails#validate', as: :emails_validation  # \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043c\u0430\u0440\u0448\u0440\u0443\u0442 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 post ':controller\/validate', action: 'validate', as: :validate_form <\/code><\/pre>\n<h5>\u041c\u0435\u0442\u043e\u0434 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438<\/h5>\n<p>  \u0412\u044b\u043d\u0435\u0441\u0435\u043c \u043b\u043e\u0433\u0438\u043a\u0443 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0432 <b>application_controller.rb<\/b>, \u0447\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u043c\u043e\u0433\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>  <b>app\/controllers\/application_controller.rb<\/b><\/p>\n<pre><code class=\"ruby\">def validator(object)   object.valid?   model = object.class.name.underscore.to_sym   field = params[model].first[0]   @errors = object.errors[field]    if @errors.empty?     @errors = true   else     name = t(&quot;activerecord.attributes.#{model}.#{field}&quot;)     @errors.map! { |e| &quot;#{name} #{e}&lt;br \/&gt;&quot; }   end end <\/code><\/pre>\n<p>  <b>app\/controllers\/emails_controller.rb<\/b><\/p>\n<pre><code class=\"ruby\">def validate   email = Email.new(email_params)   validator(email)   respond_to do |format|     format.json { render json: @errors }   end end <\/code><\/pre>\n<p>  P.S. \u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u0434\u0451\u0440\u0433\u0430\u0442\u044c \u0441\u0435\u0440\u0432\u0435\u0440 \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0432\u0432\u0435\u0434\u0451\u043d\u043d\u043e\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0441\u0438\u043c\u0432\u043e\u043b\u0435 \u0432 \u043f\u043e\u043b\u044f\u0445 \u0444\u043e\u0440\u043c\u044b, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 <code>onkeyup: false<\/code><\/p>\n<p>  <b>jQuery Validation Plugin:<\/b><br \/>  <a href=\"http:\/\/jqueryvalidation.org\">http:\/\/jqueryvalidation.org<\/a><\/p>\n<p>  <b>\u0414\u0435\u043c\u043e \u0441 \u0431\u0430\u043d\u0442\u0438\u043a\u0430\u043c\u0438:<\/b><br \/>  <a href=\"http:\/\/sandbox.alexfedoseev.com\/dry-validation\/showoff\">http:\/\/sandbox.alexfedoseev.com\/dry-validation\/showoff<\/a>    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/213077\/\"> http:\/\/habrahabr.ru\/post\/213077\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u041a\u043e\u0433\u0434\u0430 \u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u043b \u0437\u0430\u0434\u0443\u043c\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043e \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438\u043e\u0431\u0449\u0438\u0442\u044c\u0441\u044f \u043a \u043c\u0438\u0440\u0443 \u0432\u0435\u0431-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438, \u0438 \u0432\u044b\u0431\u0438\u0440\u0430\u043b \u044f\u0437\u044b\u043a, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0430\u0447\u043d\u0443, \u043e\u0434\u043d\u0430 \u0438\u0437 \u0432\u0438\u043a\u0438\u043f\u0435\u0434\u0438\u0439 \u043c\u043d\u0435 \u043d\u0430\u043f\u0435\u043b\u0430, \u0447\u0442\u043e \u0432 \u043e\u0441\u043d\u043e\u0432\u0435 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u0438\u0438 Rails \u043b\u0435\u0436\u0430\u0442 2 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430: <b>Convention over configuration (CoC)<\/b> \u0438 <b>Don\u2019t Repeat Yourself (DRY)<\/b>. \u0427\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u2014 \u044f \u0442\u043e\u0433\u0434\u0430 \u0432\u043e\u0431\u0449\u0435 \u043d\u0435 \u043f\u043e\u043d\u044f\u043b \u043e \u0447\u0451\u043c \u0440\u0435\u0447\u044c, \u0430 \u0432\u043e\u0442 \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u043e\u043d\u044f\u043b, \u043f\u0440\u0438\u043d\u044f\u043b \u0438 \u043e\u0436\u0438\u0434\u0430\u043b, \u0447\u0442\u043e \u0432 \u043d\u0435\u0434\u0440\u0430\u0445 \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430, \u044f \u043e\u0442\u044b\u0449\u0443 \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u043c\u043d\u0435 \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u043c\u043e\u0434\u0435\u043b\u0438, \u0438 \u043f\u043e\u0442\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043a\u0430\u043a \u0434\u043b\u044f front, \u0442\u0430\u043a \u0438 \u0434\u043b\u044f back \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-213077","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/213077","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=213077"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/213077\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=213077"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=213077"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=213077"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}