There is such a construction on the main page, authorization through a modal window using json. How to make li login with current_user, without reloading the page

<% if current_user %> <li><a><%= "Hello, #{current_user.fullname}" %></a></li> <li><%= link_to "Sign out", destroy_user_session_path, :method => :delete %></li> <% else %> <li><a href="#create_user_modal" class="modal_fancy">Регистрация</a></li> <li><a href="#login_modal" class="modal_fancy">Вход</a></li> <% end %> 

Jquery error output processing via json

 $("#login ").bind("ajax:success", function(event, xhr, settings){ }); class SessionsController < Devise::SessionsController respond_to :html, :json end 

Ruby 2.2 Rails 5.0

    1 answer 1

    I do not recommend doing so. Your site will have to know what exactly and how exactly to change upon successful login. This is a stateful solution, and they are characterized by a nonlinear growth in complexity of support. With the development of the project, this code will be harder and harder to maintain. Unreasonably heavier.

    Prefer stateless solutions. Reload the page - you can through turbolinks, if you want to reload instantly for the user, without a white screen of a blank page.

    • And how to reboot through turbolinks? - Silentium
    • Connect according to the instructions - github.com/turbolinks/turbolinks . In js you can insert Turbolinks.visit(window.location) . Although if you connect turbolinks, observing the recommendations in the readme - you can do without manual processing of each form - turbolinks will take on smooth transitions on the links on the website and smooth redirects - when sending forms as well. - Vitaly Emelyantsev
    • Thank you figured out, all the same, it’s a pity that everything is so complicated with ajax - Silentium
    • The difficulty is not in the ajax itself, but in the stateful update of the interface. In the frontend, until reactjs became popular - with js-frameworks of that time, porridge was just because of their stateful orientation. You have sites on Ruby on Rails, and this is great - there are turbolinks and jquery_ujs that help you to easily update the interface with Ajax, without plunging into the frontend jungle. - Vitaliy Emelyantsev