0

I have a view, that contains a submit button, and on submit I need to render a partial view in the same page. I noticed that when I use render partial in controller, the other view opens in another page. So based on this answer Rendering a partial from a controller in rails I did the following:

in my controller I added this to the main action (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

And I created distribute_payments.rjs and _distribute_payments.html.erb under views:

distribute_payments.rjs:

  page.insert_html :bottom, "distribute_payments", render(:partial=>'distribute_payments')

distribute_payments.html.erb:

hi

Now when I click on the submit button in the main view, it opens another page with this:

Element.insert("distribute_payments", { bottom: "hi" });

This is the log file:

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]

What is happening here?

Community
  • 1
  • 1
Rabah Hamzah
  • 125
  • 1
  • 9

0 Answers0