用rails link_to打开弹出窗口

时间:2017-03-24 05:52:28

标签: javascript ruby-on-rails

我试图使用rails link_to打开一个弹出窗口。但不幸的是,我遇到了一些问题。当我转到新页面时,不会显示任何弹出窗口。

我使用了rails 2.3.2

show.html.erb

<%= link_to "new payment", new_project_voucher_voucher_payment_path(@project, @voucher ), "data-toggle" => "modal", "data-target" => "#new_voucher_payment" %>

new.html.erb

<div id ="new_voucher_payment" class="modal fade"  role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">Confirmation</h4>
        <p>hello!!!!!!!!!!!!!!!!!</p>

      </div>
    </div>
  </div>
</div>

如何显示弹出窗口?

1 个答案:

答案 0 :(得分:0)

如果你想弹出一个带凭证付款的模式,新的控制器更好的方法是作为js响应新的

  

应用程序/视图/ project_vouchers / show.html.erb

<%= link_to "new payment", new_project_voucher_voucher_payment_path(@project, @voucher ) remote: true do %>
....
<div class="modal fade" id="new_voucher_payment" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

  

应用程序/视图/ project_vouchers / voucher_payments.js.erb

$("#new_voucher_payment").html("<%=j render 'voucher_payment', object: @voucher_payments %>");
$('#new_voucher_payment').modal('show');
  

应用程序/视图/ project_vouchers / _voucher_payment_form.html.erb

  <div class="modal-dialog">
   <div class="modal-content">
     <div class="modal-header">
      <h4 class="modal-title">Confirmation</h4>
      <p>hello!!!!!!!!!!!!!!!!!</p>
      # your code comes here  
     </div>
   </div>
 </div>
  

应用程序/控制器/ voucher_payments_controller.rb

class VoucherPaymentsController < ApplicationController
  ....
  def new
    ....
    respond_to do |format|
      format.html {
        # write the code for html response
      }
      format.js {
       @voucher_payments
      }
    end
  end
  ....
end