I have created a modal form that submits values via remote => true (AJAX) and stores it in the database. This functionality works as records are saved in the database. Here is my controller code:
respond_to :js, only: [:create_agent_confirmation]
def create_agent_confirmation
if @agent_confirm.validate(params[:agent_confirm])
@agent_confirm.save
respond_with(@agent_confirm, :location => root_path)
else
respond_with(@agent_confirm, :location => contact_path)
end
end
And in my Modal (View):
#agent_confirm_modal.small.reveal-modal{"data-reveal" => ""}
= simple_form_for [:customer, @agent_confirm], :url => create_agent_confirm_customers_path, :remote => true do |f|
.row
.sub-headline-secondary
.padding-16-balanced-bottom
= "Agent Confirmation"
.col-1-1-1.padding-16-all
.padding-12-bottom
= f.input :detail_verification, as: :boolean, label: "I have confirmed/updated the customer's details"
.padding-12-bottom
= f.input :document_verification, as: :boolean, label: "I have confirmed/updated the customer's documentation"
%a.close-reveal-modal= "×".html_safe
.padding-16-all.margin-gutter-bottom
= f.button :submit, "Submit", class: "button right tiny radius"
The questions that I have:
- How do I populate the form with relevant validation errors, using js?
- After saving the record successfully, I want to redirect to an entirely different page. The controller code listed above returns an error in Firebug stating that the relevant template for "create_agent_confirmation" could not be found (even though I indicate that I need to return to root_path).
PS* I only need to be redirected if the record has been successfully created.
Any ideas?