[英]how to open popup box in rails4 link_to
嗨,我想打開我認為是的彈出框
<%=link_to 'show',edit_interview_round_path(round), :remote => true%>
<div id="popup">
</div>
並寫在我的控制器上
def edit
@interview_round = InterviewRound.where(id: params[:id]).first
respond_to do |format|
format.js
end
end
而且我有edit.js.erb
$("#popup").html('<%= escape_javascript(render 'interview_rounds/form') %>');
在views_rounds / edit視圖中已經寫了這個
<%= render 'form' %>
在views_rounds / _form視圖中已經寫了這個
<%= form_for @interview_round do |f| %>
<div class='modal'>
<%= f.text_field :name, :class => 'form-control' %>
<label for='name'>Name</label>
</div>
<div class='input-field col s12' >
<%= f.text_field :question_1, :class => 'form-control' %>
<label for='name'>Name</label>
</div>
<div class='col s12 center-align'>
<%= button_tag(:class => "btn waves-effect waves-light btn-large custom_btn_gray") do %>
Submit <i class="mdi-content-send right"></i>
<% end %>
</div>
<% end %>
所以現在當我單擊“顯示”時,它不會打開彈出窗口,它在同一頁面上顯示了編輯視圖,我想在彈出框中顯示它,請指導我如何執行此操作。 提前致謝!
嘗試這樣格式化部分渲染代碼:
$("#popup").html("<%= j render( :partial => 'interview_rounds/form' ) %>");
看起來您嵌套了單引號,這可能是問題所在。 您的代碼當前設置為在ID為popup的div中的同一頁面上呈現部分視圖。
如果要在新窗口中渲染,請嘗試以下操作:
var wind = window.open("", "popupWindow", "width=600,height=600");
wind.document.write("<%= j render( :partial => 'interview_rounds/form' ) %>");
如果表單在#popup div中正確呈現,並且您需要模態或覆蓋效果,則只需將彈出div設置為模態樣式就可以了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.