簡體   English   中英

將.js控制器請求呈現為html

[英]Render a .js controller request as html

我在我的Rails應用程序中有一個before_filter ,如果用戶在提交請求時以html或js格式注銷, login_url將用戶發送到login_url

我想我的format.js產生相同的結果format.html ,在以下情況下渲染“通知”布局視圖。 我怎樣才能做到這一點?

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

你可以強制使用這樣的可用格式:

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

編輯:

您需要的是文檔的某些部分被響應替換。 這是通過使用執行該作業的javascript響應來完成的:

在你的控制器中:

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

在您的login.js視圖中:

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

......或類似的東西

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM