Do this on the button that is supposed to trigger the modal
<%= link_to "login", new_user_session_path, :remote => true, 'data-toggle' => 'modal', 'data-target' => '#your_modal_id', :class => "btn btn-primary", :method: 'get' %>
For this to work you will have to overwrite devise sessions #new
and registrations #new
to respond to ajax requests. you can do this by introducing a respond_to block on both of these actions like this
respond_to do |format|
format.js
end
then in your app/views/devise/registrations
and app/views/devise/sessions
create new.js.erb
files. You can remove the login and sign-up forms from the modal and put the javascript to render the forms inside the modals in these new.js.erb
files.
You can remove the form from the modal and in modal-body
you put a loading gif. You can instead put the form in a partial and place it in app/views/devise/sessions/_login_form.html.erb
. Then in app/views/devise/sessions/new.js.erb
you do something like this.
$('#your_modal_id').remove-data
$('.modal-header').html ("<%= escape_javascript(render'/path/to/partial/with/header/content') %>");
$('.modal-body').html ("<%= escape_javascript(render '/path/to/partial')) %>");
$('.modal-footer').html ("<%= escape_javascript(render '/path/to/partial')) %>");