1
votes

I'm re-rendering a partial after submitting a remote: true form, but my problem is that it seems to re-render the partial BEFORE fully completing the form's update action. As a result, it renders old data on the page, and shows updated info only after a full refresh (or when I submit the form yet again). Is there a way to force the application to re-render the partial after everything is completed, in order to display only the new info? Or am I missing a step here?

update.js.erb:

$("#methods").html("<%= escape_javascript(render partial: 'methods') %>");

owner_controller.rb

respond_to :html, :js, :json

def update
  if owner.update_attributes(owner_params)
    respond_to do |format|
      format.js
    end
  else
    fail_update
  end
end
2
Use the 'locals' option in render to pass the variables to the view. Such as render partial: "form", locals: {user: @user}...More info here: guides.rubyonrails.org/… - bkunzi01

2 Answers

0
votes
$("#methods").html("<%= escape_javascript(render partial: 'methods', locals: {owner: @owner}) %>");

and assuming you are setting owner in a before action, change the variable you set from owner to @owner.

0
votes

in update.js.erb

$("#methods").html("<%= j(render partial: 'methods') %>");
<% unless @owner.errors.present? %> 
 $('#some_form')[0].reset()
<% end %>