我在我的Rails应用程序中使用bootstrap模式。我现在的代码:
索引页:
<button type="button" class="btn btn-primary" data-amount="30" data-toggle="modal" data-target=".bs-example-modal-sm">Process Payment</button>
<%= render 'point_transactions/payment'%>
Jquery Bootstrap模式:
$('#myModal').on('shown.bs.modal', function() {
$('#myInput').focus()
})
我的表格处理Braintree付款
<div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<%=form_for point_transactions_path, url: point_transactions_path do |f| %>
<div id="payment-form"></div>
<br>
<%=f .submit 'Submit', class: 'btn btn-success btn-lg' %>
<%end%>
</div>
</div>
</div>
<script>
braintree.setup('____', "dropin", {
container: "payment-form"
});
</script>
每次加载索引页面时,我都会呈现付款表单。如果我点击按钮,jQuery模式将弹出表单。
如何在用户点击按钮后呈现表单 - 我想它会出现在jQuery中?
我的按钮包括data-amount =“30”。如何通过jQuery将参数data-amount传递给我的控制器?
感谢您的帮助。
答案 0 :(得分:0)
作为回答第二个问题的尝试,我假设您希望将值form_for point_transactions_path, url: point_transactions_path(amount: 30) do |f|
返回给您的控制器。如果是这种情况,您可以将其作为查询参数添加到您的网址。
params[:amount] #=> 30
回到你的控制器,你可以得到它
public function create_goal(){
$id=$this->input->post('c_id');
$result_updated_record = $this->course_model->get_last_course_rec($id);
if($result_updated_record!='false')
{
echo json_encode($result_updated_record);
}
else
{
echo json_encode($result_updated_record);
}
}
答案 1 :(得分:0)
问题以下列方式解决:
jQuery的:
$(document).on("click", ".open-AddPointDialog", function () {
var myPoint = $(this).data('points');
$(".modal-body #point_transaction_points").val( myPoint );
});
HTML POP UP表格
<div class="modal fade" id="addPointDialog" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-body">
<%=form_for @point_transaction , url: point_transactions_path do |f| %>
<div id="payment-form"></div>
<br>
<%= f.hidden_field :points %>
<%= f.submit 'Submit', class: 'btn btn-success btn-lg' %>
<%end%>
</div>
</div>
</div>
</div>
按钮
<a data-toggle="modal" data-points="30" class="open-AddPointDialog btn btn-success big" href="#addPointDialog"><i class="fa fa-hand-o-right hided-icon big"></i> Buy Points </a>