My app has a modal sign in form that I display using ajax:
<% if !current_user %>
<%= link_to "Sign in", signin_path, remote: true %>
<% end %>
routes.rb
get 'signin', to: 'static_pages#signin', as: 'signin'
static_pages_controller.rb
def signin
respond_to do |format|
format.html { render :action => 'signin.js.erb' }
format.js { render :action => 'signin.js.erb' }
end
end
signin.js.erb
$('#modalPlaceholder').html("<%= j render(partial: '/static_pages/signin') %>");
$('#modalPlaceholder').show();
This works well.
I would now like to intercept actions that require user sign in and display this modal. In my application controller I have:
application_controller.rb
def require_signin!
if current_user.nil?
render :action => '../static_pages/signin.js.erb'
end
end
helper_method :require_signin!
This works when the originating action is remote: :true and rails simply redirects it however when the originating action is a standard request the action is intercepted correctly by the application controller however the modal is displayed on screen in raw html and not loaded correctly.