{"id":216837,"date":"2014-03-24T12:23:03","date_gmt":"2014-03-24T08:23:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=216837"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=216837","title":{"rendered":"<span class=\"post_title\">Devise: \u0432\u0445\u043e\u0434 \u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0432 \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u044b\u0445 \u043e\u043a\u043d\u0430\u0445<\/span>"},"content":{"rendered":"<div class=\"content html_format\"> \t\t\t\u041d\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u044b\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043d \u0447\u0435\u0440\u0435\u0437 \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u044b\u0435 \u043e\u043a\u043d\u0430 \u0438 \u00ab\u043e\u0431\u044b\u0447\u043d\u044b\u0435\u00bb \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432. \u041f\u043e\u0441\u043b\u0435 \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e\u043d\u044f\u043b, \u0447\u0442\u043e \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0442\u043e, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e. \u0422\u0430\u043a <a href=\"http:\/\/strandcode.com\/2013\/08\/23\/embedding-devise-forms-in-twitter-bootstrap-modals\/\">\u0437\u0434\u0435\u0441\u044c<\/a> \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043c\u0435\u0449\u0430\u044e\u0442 \u0444\u043e\u0440\u043c\u0443 \u0432 \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043a\u043d\u043e (\u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u0443\u044f\u0441\u044c <a href=\"https:\/\/github.com\/plataformatec\/devise\/wiki\/How-To:-Display-a-custom-sign_in-form-anywhere-in-your-app\">\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435\u0439 \u0438\u0437 wiki devise<\/a>), \u0430 \u0442\u0443\u0442 (<a href=\"http:\/\/natashatherobot.com\/devise-rails-sign-in\/\">\u0432\u0445\u043e\u0434<\/a> \u0438 <a href=\"http:\/\/natashatherobot.com\/devise-sign-up-ajax-rails\/\">\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f<\/a>) \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442 \u043c\u0435\u0442\u043e\u0434\u044b \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u0445 devise \u0442\u0430\u043a, \u0447\u0442\u043e \u043e\u043d\u0438 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u043e\u0442\u0434\u0430\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e json \u0438 \u0434\u043b\u044f \u00ab\u043d\u0435\u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0433\u043e\u00bb \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0441 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439 \u0444\u043e\u0440\u043c\u0430\u0442\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0440\u0435\u0448\u0438\u043b \u043f\u043e\u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u043d\u043e\u0432\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 2 \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u0432 \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0438 \u0433\u0440\u044f\u0437\u043d\u044b\u0445 \u0445\u0430\u043a\u043e\u0432.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h4>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/h4>\n<p>  <\/p>\n<ol>\n<li> \u0413\u0435\u043d\u0435\u0440\u0438\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0431\u0435\u0437 \u0442\u0435\u0441\u0442\u043e\u0432 \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 <i>bundle install<\/i>: <code>rails new devise_modal -B -T<\/code><\/li>\n<li> \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0435 \u0433\u0435\u043c\u044b \u0432 <b>Gemfile<\/b>:<br \/> \n<ul>\n<li><code>gem 'therubyracer', platforms: :ruby<\/code><br \/>   <code>gem &quot;less-rails&quot;<\/code><br \/>   <code>gem 'twitter-bootstrap-rails', branch: 'bootstrap3'<\/code> \u2014 \u0434\u043b\u044f \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u044b\u0445 \u043e\u043a\u043e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <a href=\"https:\/\/github.com\/seyhunak\/twitter-bootstrap-rails\">bootstrap<\/a><\/li>\n<li><code>gem 'devise'<\/code> \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0447\u0435\u0440\u0435\u0437 <a href=\"https:\/\/github.com\/plataformatec\/devise\">devise<\/a><\/li>\n<\/ul>\n<p>   \u0418 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0432\u0441\u0451: <code>bundle install<\/code>   <\/li>\n<li> \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0435 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b<br \/>   <code>rails g bootstrap:install static<\/code>, \u00abstatic\u00bb \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0438\u0447\u0435\u0433\u043e \u043c\u0435\u043d\u044f\u0442\u044c \u0432 \u0441\u0442\u0438\u043b\u044f\u0445 <i>bootstrap<\/i>&#8216;\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u043c <br \/>   <code>rails g devise:install; rails g devise User; rake db:migrate<\/code> \u2014 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c <i>devise<\/i> \u0438 \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\n<\/li>\n<li> \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0433\u043b\u0430\u0432\u043d\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443:<br \/>   <code>rails g controller welcome index --no-helper --no-assets<\/code><br \/>   \u0412 <b>config\/routes.rb<\/b> \u043f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c <i>index<\/i> \u043a \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435:<br \/>   <code>root 'welcome#index'<\/code>   <\/li>\n<\/ol>\n<p>  \u0412 \u043a\u043e\u043d\u0446\u0435 \u044d\u0442\u043e\u0433\u043e \u044d\u0442\u0430\u043f\u0430 \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0441 \u0444\u043e\u0440\u043c\u0430\u043c\u0438 \u0432\u0445\u043e\u0434\u0430\/\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043d\u0430 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0441\u0441\u044b\u043b\u043a\u0430\u0445 \u0434\u043b\u044f <i>devise<\/i>: <code>users\/sign_in<\/code> \u0438 <code>users\/sign_up<\/code>.<\/p>\n<h4>\u041c\u043e\u0434\u0430\u043b\u044c\u043d\u044b\u0435 \u043e\u043a\u043d\u0430 \u0434\u043b\u044f \u0444\u043e\u0440\u043c<\/h4>\n<p>  \u0412 \u0444\u043e\u0440\u043c\u0430\u0445 \u043d\u0435\u0442\u0443 \u043d\u0438\u0447\u0435\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 <i>devise<\/i>&#8216;\u043e\u0432\u0441\u043a\u0438\u0435 \u0441\u0434\u0435\u043b\u0430\u0432 \u0438\u0445 <i>remote<\/i> \u0438 \u043f\u043e\u043c\u0435\u043d\u044f\u0432 \u0444\u043e\u0440\u043c\u0430\u0442 \u043d\u0430 <i>json<\/i>. \u0414\u0430\u043b\u044c\u0448\u0435 \u0434\u0435\u043b\u0430\u0435\u043c \u0438\u0445 \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u044b\u043c\u0438, \u043e\u0431\u0435\u0440\u043d\u0443\u0432 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u044b <i>bootstrap<\/i>&#8216;\u0430. \u0412 \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438\u0441\u044c \u0442\u0430\u043a\u0438\u0435 <i>partial<\/i>&#8216;\u044b:<br \/>  <b>app\/views\/shared\/_sign_in.html.erb<\/b>  <\/p>\n<pre><code class=\"ruby\">&lt;div class=&quot;modal hide fade in&quot; id=&quot;sign_in&quot;&gt;      &lt;div class=&quot;modal-header&quot;&gt;     &lt;button class=&quot;close&quot; data-dismiss=&quot;modal&quot;&gt;x&lt;\/button&gt;     &lt;h2&gt;Sign in&lt;\/h2&gt;   &lt;\/div&gt;    &lt;div class=&quot;modal-body&quot;&gt;     &lt;%= form_for(resource, as: resource_name, url: session_path(resource_name), html:{id: 'sign_in_user', :'data-type' =&gt; 'json'}, remote: true) do |f| %&gt;       &lt;div&gt;         &lt;%= f.label :email %&gt;&lt;br \/&gt;         &lt;%= f.email_field :email, autofocus: true %&gt;       &lt;\/div&gt;        &lt;div&gt;         &lt;%= f.label :password %&gt;&lt;br \/&gt;         &lt;%= f.password_field :password, autocomplete: &quot;off&quot; %&gt;       &lt;\/div&gt;        &lt;% if devise_mapping.rememberable? -%&gt;         &lt;div&gt;           &lt;%= f.check_box :remember_me %&gt;           &lt;%= f.label :remember_me %&gt;         &lt;\/div&gt;       &lt;% end -%&gt;        &lt;div&gt;         &lt;%= f.submit &quot;Sign in&quot; %&gt;       &lt;\/div&gt;     &lt;% end %&gt;   &lt;\/div&gt;   &lt;div class=&quot;modal-footer&quot;&gt;   &lt;\/div&gt; &lt;\/div&gt; <\/code><\/pre>\n<p>  <b>app\/views\/shared\/_sign_up.html.erb<\/b>  <\/p>\n<pre><code class=\"ruby\">&lt;div class=&quot;modal hide fade in&quot; id=&quot;sign_up&quot;&gt;      &lt;div class=&quot;modal-header&quot;&gt;     &lt;button class=&quot;close&quot; data-dismiss=&quot;modal&quot;&gt;x&lt;\/button&gt;     &lt;h2&gt;Sign up&lt;\/h2&gt;   &lt;\/div&gt;    &lt;div class=&quot;modal-body&quot;&gt;     &lt;%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: {id: 'sign_up_user', :'data-type' =&gt; 'json'}, remote: true) do |f| %&gt;       &lt;%= devise_error_messages! %&gt;        &lt;div&gt;         &lt;%= f.label :email %&gt;&lt;br \/&gt;         &lt;%= f.email_field :email, autofocus: true %&gt;       &lt;\/div&gt;        &lt;div&gt;         &lt;%= f.label :password %&gt;&lt;br \/&gt;         &lt;%= f.password_field :password, autocomplete: &quot;off&quot; %&gt;       &lt;\/div&gt;        &lt;div&gt;         &lt;%= f.label :password_confirmation %&gt;&lt;br \/&gt;         &lt;%= f.password_field :password_confirmation, autocomplete: &quot;off&quot; %&gt;       &lt;\/div&gt;        &lt;div&gt;&lt;%= f.submit &quot;Sign up&quot; %&gt;&lt;\/div&gt;     &lt;% end %&gt;   &lt;\/div&gt;   &lt;div class=&quot;modal-footer&quot;&gt;   &lt;\/div&gt; &lt;\/div&gt; <\/code><\/pre>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u044d\u0442\u0438\u0445 \u0444\u0430\u0439\u043b\u043e\u0432 \u0438 \u0441\u0441\u044b\u043b\u043e\u043a \u0434\u043b\u044f \u0438\u0445 \u0432\u044b\u0437\u043e\u0432\u0430 \u0432 <i>layout<\/i>:  <\/p>\n<pre><code class=\"ruby\">&lt;%= link_to &quot;Sign in&quot;, &quot;#sign_in&quot;, &quot;data-toggle&quot; =&gt; &quot;modal&quot;, :class =&gt; 'btn btn-small' %&gt; &lt;%= link_to &quot;Sign up&quot;, &quot;#sign_up&quot;, &quot;data-toggle&quot; =&gt; &quot;modal&quot;, :class =&gt; 'btn btn-small' %&gt; &lt;%= render 'shared\/sign_in' %&gt; &lt;%= render 'shared\/sign_up' %&gt; <\/code><\/pre>\n<p>  \u0410 \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043e\u0431\u043b\u0430\u0433\u043e\u0440\u043e\u0434\u0438\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e, \u0441\u0434\u0435\u043b\u0430\u0432 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043d\u0430 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u044e\u0437\u0435\u0440\u0430:<br \/>  <b>app\/views\/layouts\/application.html.erb<\/b>  <\/p>\n<pre><code class=\"ruby\">&lt;% if current_user %&gt;   &lt;%= &quot;Hello, #{current_user.email}&quot; %&gt;   &lt;%= link_to &quot;Sign out&quot;, destroy_user_session_path, :method =&gt; :delete %&gt; &lt;% else %&gt;   &lt;%= link_to &quot;Sign in&quot;, &quot;#sign_in&quot;, &quot;data-toggle&quot; =&gt; &quot;modal&quot;, :class =&gt; 'btn btn-small' %&gt;   &lt;%= link_to &quot;Sign up&quot;, &quot;#sign_up&quot;, &quot;data-toggle&quot; =&gt; &quot;modal&quot;, :class =&gt; 'btn btn-small' %&gt;   &lt;%= render 'shared\/sign_in' %&gt;   &lt;%= render 'shared\/sign_up' %&gt; &lt;% end %&gt; <\/code><\/pre>\n<p>  \u0427\u0442\u043e\u0431\u044b \u0432\u0441\u0451 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432 <i>application_helper<\/i>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442 <i>resource<\/i> \u0438 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u043d\u0438\u043c <a href=\"https:\/\/github.com\/plataformatec\/devise\/wiki\/How-To:-Display-a-custom-sign_in-form-anywhere-in-your-app\">\u0432\u0435\u0449\u0438<\/a> \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430:<br \/>  <b>app\/helpers\/application_helper.rb<\/b>  <\/p>\n<pre><code class=\"ruby\">def resource_name   :user end  def resource   @resource ||= User.new end  def devise_mapping   @devise_mapping ||= Devise.mappings[:user] end <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0435\u0441\u0442\u044c \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u044b\u0435 \u0444\u043e\u0440\u043c\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0441 \u043b\u044e\u0431\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0432\u0445\u043e\u0434\u0438\u0442\u044c \u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f. \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b <i>devise<\/i> \u043d\u0430 \u044d\u0442\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432 \u043e\u0442\u0432\u0435\u0442 \u043d\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u043b html \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b.<\/p>\n<h4>JSON \u043e\u0442\u0432\u0435\u0442\u044b \u043e\u0442 devise<\/h4>\n<p>  \u0412 \u0433\u0435\u043c\u0435 <i>devise<\/i> \u0437\u0430 \u043e\u0448\u0438\u0431\u043a\u0438 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441\u043e \u0432\u0445\u043e\u0434\u043e\u043c \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 <a href=\"https:\/\/github.com\/plataformatec\/devise\/blob\/master\/lib\/devise\/failure_app.rb\">FailureApp<\/a>. \u041f\u0440\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u0438 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 <i>SessionsController<\/i>&#8216;\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430 \u0432\u0445\u043e\u0434, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <a href=\"https:\/\/github.com\/plataformatec\/devise\/blob\/master\/lib\/devise\/failure_app.rb#L33\">respond<\/a>, \u0433\u0434\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/github.com\/plataformatec\/devise\/blob\/master\/lib\/devise\/failure_app.rb#L136\">http_auth?<\/a> \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f: \u043d\u0443\u0436\u043d\u043e \u0441\u043b\u0430\u0442\u044c 401 \u0441\u0442\u0430\u0442\u0443\u0441 \u0438\u043b\u0438 \u0436\u0435 \u043f\u0435\u0440\u0435\u0430\u0434\u0440\u0435\u0441\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u0434\u0440\u0443\u0433\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443. \u0422\u0430\u043a \u043a\u0430\u043a \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0443 <i>devise<\/i>&#8216;\u0430:<br \/>  <b>config\/initializers\/devise.rb<\/b>  <\/p>\n<pre><code class=\"ruby\">config.http_authenticatable_on_xhr = true <\/code><\/pre>\n<p> \u0442\u043e \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f 401.<br \/>  RegistrationsController \u0436\u0435 \u0432 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 AJAX \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u0440\u0438\u0441\u044b\u043b\u0430\u0435\u0442 html \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443, \u0447\u0442\u043e\u0431\u044b \u044d\u0442\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0435\u0433\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u2014 \u0443\u043a\u0430\u0436\u0435\u043c \u044f\u0432\u043d\u043e, \u043a\u0430\u043a\u0438\u0435 \u0444\u043e\u0440\u043c\u0430\u0442\u044b \u043d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0442:<br \/>  <code>rails g controller Registrations --no-helper --no-assets --no-views<\/code><br \/>  <b>config\/routes.rb<\/b>  <\/p>\n<pre><code class=\"ruby\">devise_for :users, controllers: {registrations: 'registrations'} <\/code><\/pre>\n<p>  <b>app\/controllers\/registrations_controller.rb<\/b>  <\/p>\n<pre><code class=\"ruby\">class RegistrationsController &lt; Devise::RegistrationsController   respond_to :html, :json end <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438 \u043d\u0435\u0443\u0434\u0430\u0447\u043d\u043e\u0439 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f 422 \u0441\u0442\u0430\u0442\u0443\u0441 \u0441 \u0442\u0435\u043a\u0441\u0442\u0430\u043c\u0438 \u043e\u0448\u0438\u0431\u043e\u043a \u0432 <i>responseJSON[&#8216;errors&#8217;]<\/i>, \u0430 \u043f\u0440\u0438 \u0443\u0434\u0430\u0447\u043d\u043e\u0439 \u2014 201. \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0434\u043b\u044f <i>SessionsController<\/i>&#8216;\u0430 \u043f\u0440\u0438 \u0443\u0434\u0430\u0447\u043d\u043e\u043c \u0432\u0445\u043e\u0434\u0435 \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u0443\u0441, \u0430 \u043d\u0435 html-\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u00ab\u043d\u0430\u0443\u0447\u0438\u043c\u00bb \u0438 \u0435\u0433\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0440\u0435\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 <i>json<\/i> \u0437\u0430\u043f\u0440\u043e\u0441\u044b:<br \/>  <code>rails g controller Sessions --no-helper --no-assets --no-views<\/code><br \/>  <b>config\/routes.rb<\/b>  <\/p>\n<pre><code class=\"ruby\">devise_for :users, controllers: {sessions: 'sessions', registrations: 'registrations'} <\/code><\/pre>\n<p>  <b>app\/controllers\/sessions_controller.rb<\/b>  <\/p>\n<pre><code class=\"ruby\">class SessionsController &lt; Devise::SessionsController   respond_to :html, :json end <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c <i>javascript<\/i>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442\u044b \u043e\u0442 \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u044b\u0445 \u0444\u043e\u0440\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u0430\u043a\u043e\u0439:<br \/>  <b>app\/assets\/javascripts\/welcome.js.coffee<\/b>  <\/p>\n<pre><code class=\"coffeescript\">$ -&gt;   $(&quot;form#sign_in_user, form#sign_up_user&quot;).bind(&quot;ajax:success&quot;, (event, xhr, settings) -&gt;     $(this).parents('.modal').modal('hide')   ).bind(&quot;ajax:error&quot;, (event, xhr, settings, exceptions) -&gt;     error_messages = if xhr.responseJSON['error']       &quot;&lt;div class='alert alert-danger pull-left'&gt;&quot; + xhr.responseJSON['error'] + &quot;&lt;\/div&gt;&quot;     else if xhr.responseJSON['errors']       $.map(xhr.responseJSON[&quot;errors&quot;], (v, k) -&gt;         &quot;&lt;div class='alert alert-danger pull-left'&gt;&quot; + k + &quot; &quot; + v + &quot;&lt;\/div&gt;&quot;       ).join &quot;&quot;     else       &quot;&lt;div class='alert alert-danger pull-left'&gt;Unknown error&lt;\/div&gt;&quot;     $(this).parents('.modal').children('.modal-footer').html(error_messages)   ) <\/code><\/pre>\n<p>  \u041f\u0440\u0438 \u0432\u0445\u043e\u0434\u0435 \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443 \u0432 <i>alert<\/i>, \u0430 \u043f\u0440\u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u2014 \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0443, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432 <i>footer<\/i>&#8216;\u0435. \u041f\u0440\u0438 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0431\u0438\u0440\u0430\u0435\u043c \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u0443\u044e \u0444\u043e\u0440\u043c\u0443 (\u043c\u043e\u0436\u043d\u043e \u0435\u0449\u0451 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0431\u043b\u043e\u043a \u0432 <i>layout<\/i>&#8216;\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f (\u043e\u043d\u0438 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0442 \u0432 \u043e\u0442\u0432\u0435\u0442\u0435)).<br \/>  \u0422\u0435\u043f\u0435\u0440\u044c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u043e\u0442\u0434\u0430\u044e\u0442 \u043e\u0442\u0432\u0435\u0442\u044b \u0432 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435, \u043a\u0430\u043a \u0438 \u0434\u043b\u044f \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u044b\u0445 \u0444\u043e\u0440\u043c \u2014 <i>json<\/i>, \u0442\u0430\u043a \u0438 \u0434\u043b\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445(<i>users\/sign_in<\/i>, <i>users\/sign_up<\/i>) \u2014 <i>html<\/i>. \u0418 \u0432\u0441\u0451, \u0447\u0442\u043e \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u043b\u043e\u0441\u044c \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u043b\u043e\u0441\u044c \u2014 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b, \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0432 \u043d\u0430\u0431\u043e\u0440 \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u0432:  <\/p>\n<pre><code class=\"ruby\">respond_to :html, :json <\/code><\/pre>\n<p>  <\/p>\n<h6>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/h6>\n<p>  \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u0438\u0441\u0430\u043b\u043e\u0441\u044c \u043d\u0430 rails 4, \u043d\u043e \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u0434\u043b\u044f 3.2 \u0431\u0443\u0434\u0443\u0442 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b: \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0441\u044f <code>bundle install<\/code> \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0443\u0434\u0430\u043b\u0438\u0442\u044c <code>public\/index.html<\/code> \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0443\u0442\u044c \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u0443\u044e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0447\u0443\u0442\u044c \u0438\u043d\u0430\u0447\u0435:<br \/>  <b>config\/routes.rb<\/b>  <\/p>\n<pre><code class=\"ruby\">root to: 'welcome#index' <\/code><\/pre>\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\/216837\/\"> http:\/\/habrahabr.ru\/post\/216837\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\"> \t\t\t\u041d\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u044b\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043d \u0447\u0435\u0440\u0435\u0437 \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u044b\u0435 \u043e\u043a\u043d\u0430 \u0438 \u00ab\u043e\u0431\u044b\u0447\u043d\u044b\u0435\u00bb \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432. \u041f\u043e\u0441\u043b\u0435 \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e\u043d\u044f\u043b, \u0447\u0442\u043e \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0442\u043e, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e. \u0422\u0430\u043a <a href=\"http:\/\/strandcode.com\/2013\/08\/23\/embedding-devise-forms-in-twitter-bootstrap-modals\/\">\u0437\u0434\u0435\u0441\u044c<\/a> \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043c\u0435\u0449\u0430\u044e\u0442 \u0444\u043e\u0440\u043c\u0443 \u0432 \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043a\u043d\u043e (\u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u0443\u044f\u0441\u044c <a href=\"https:\/\/github.com\/plataformatec\/devise\/wiki\/How-To:-Display-a-custom-sign_in-form-anywhere-in-your-app\">\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435\u0439 \u0438\u0437 wiki devise<\/a>), \u0430 \u0442\u0443\u0442 (<a href=\"http:\/\/natashatherobot.com\/devise-rails-sign-in\/\">\u0432\u0445\u043e\u0434<\/a> \u0438 <a href=\"http:\/\/natashatherobot.com\/devise-sign-up-ajax-rails\/\">\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f<\/a>) \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442 \u043c\u0435\u0442\u043e\u0434\u044b \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u0445 devise \u0442\u0430\u043a, \u0447\u0442\u043e \u043e\u043d\u0438 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u043e\u0442\u0434\u0430\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e json \u0438 \u0434\u043b\u044f \u00ab\u043d\u0435\u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0433\u043e\u00bb \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0441 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439 \u0444\u043e\u0440\u043c\u0430\u0442\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0440\u0435\u0448\u0438\u043b \u043f\u043e\u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u043d\u043e\u0432\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 2 \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u0432 \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0438 \u0433\u0440\u044f\u0437\u043d\u044b\u0445 \u0445\u0430\u043a\u043e\u0432.  <\/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-216837","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/216837","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=216837"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/216837\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=216837"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=216837"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=216837"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}