Yes, using ajax is a good thing in this case. As reported, company data is successfully updated through ajax.
What you can do is do json in the update action if the current update is successful, and submit the new form as json.
def update @company = Company.find(params[:id]) respond_to do |format| if @company.update_attributes(params[:company]) format.json { render json: { success: true, html: render_to_string('_form.html.slim', layout: false) } } format.html { redirect_to @company, notice: 'Company was successfully updated.' } else ...
You can access json in js and replace the current form element.
$('#company_form').live 'ajax:success', (event,data) -> $('#current_company_form').html(data.html) if(data.success == true)
Let me know if this helps.
source share