我有一个包含提交按钮的视图,在提交时我需要在同一页面中呈现部分视图。我注意到当我在控制器中使用render partial时,另一个视图在另一个页面中打开。所以基于这个答案 Rendering a partial from a controller in rails 我做了以下事情:
在我的控制器中,我将其添加到主要操作(manage_payments):
def manage_payments
@guardian = Guardian.find(params[:id])
@students=Student.find_all_by_sibling_id(@guardian.ward_id)
if request.post?
@total_amount=params[:total]
@no_payments=params[:no_payments]
respond_to do |format|
format.js { render :action => 'distribute_payments' }
end
end
我在views下创建了distribute_payments.rjs和_distribute_payments.html.erb:
distribute_payments.rjs:
page.insert_html :bottom, "distribute_payments", render(:partial=>'distribute_payments')
distribute_payments.html.erb:
hi
现在当我点击主视图中的提交按钮时,它会打开另一个页面:
Element.insert("distribute_payments", { bottom: "hi" });
这是日志文件:
Processing ParentWiseFeePaymentsController#manage_payments (for 192.168.1.112 at 2015-10-07 13:50:11) [POST]
Parameters: {"payments"=>{"no_payments"=>"2"}, "controller"=>"parent_wise_fee_payments", "action"=>"manage_payments", "id"=>"4", "commit"=>"► Generate", "authenticity_token"=>"4ISuvzv03vPyJqCYS6wNwTUcHLDpQ8lLSqCh8gfb4TA=", "no_payments"=>"2"}
Username : admin Role : Admin
Rendering parent_wise_fee_payments/distribute_payments
Completed in 13ms (View: 1, DB: 1) | 200 OK [http://acmeschool.acme.local/parent_wise_fee_payments/manage_payments/4]
这里发生了什么?