gpt4 book ai didi

javascript - 使用 Rails link_to 打开弹出窗口

转载 作者:行者123 更新时间:2023-11-28 04:50:03 25 4
gpt4 key购买 nike

我试图使用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>

如何让弹出窗口出现?

最佳答案

如果你想弹出一个带有优惠券支付的模式,新的 Controller 更好的方法是响应新的js

app/views/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">

app/views/project_vouchers/voucher_payments.js.erb

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

app/views/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>

app/controllers/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

关于javascript - 使用 Rails link_to 打开弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42992329/

25 4 0
文章推荐: javascript - 如果输入的文本不在列表中,Angularjs typeahead 显示 'add' 选项
文章推荐: html - 如何用边界边上的链接创建一个圆
文章推荐: javascript - 滚动到下一个
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com