Issue .js controller request as html

I have an application before_filterin my Rails application that sends users to login_urlif they log out when they send a request (in html or js format).

I would like mine to format.jsgive an identical result format.html, in the following case, to display the view with the notification layout. How can i do this?

respond_to do |format|
  format.js
  format.html{ render :layout => "notice" }
end
+3
source share
1 answer

you can force the used formats:

respond_to do |format|
  format.js   { render :layout => "notice", :formats => [:html] }
  format.html { render :layout => "notice" }
end

EDIT:

What you need is part of the document replaced by the answer. This is done using javascript that does the job:

In your controller:

respond_to do |format|
  format.js
  format.html { render :layout => "notice" }
end

In your view login.js:

$('#whatever').html('<%= escape_javascript( render :login, formats: [ :html ]) %>')

... or something similar

+5

All Articles