4

I have a form which is always submitting the form to the "update" function in the controller, and I have created this form using "remote_form_for" tag. In this form I have objects from different tables, and from this form I want to submit entire form data to another function(not to the "update" function) via AJAX request.

I have tried many methods including using submit tag with action

<% remote_form_for @employee, :url => organization_employee_path(@organization, @employee), :method => :put do |employee_form| %>
  // form objects and other functionalities
     ....
     ....  
         // views inside the forms
         <div id="employee_header_div">
           <%= render :partial => "employee_header", :locals => {:employee => @employee} %>
         </div>
         ...
         ... 
     <%= submit_tag "page_level_validation", :id => "page_level_validation" , :action=>"validate"%>
 <% end %>

But the Ajax request always calling the same "update" function.

It would be very helpful, if anyone helps to resolve this issue.

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
Sushanth CS
  • 2,412
  • 3
  • 23
  • 23
  • can you please post your view code? Also, the Rails version you are using... `form_remote_for` is deprecated in Rails 3 – Jasdeep Singh Nov 24 '10 at 05:53
  • I am using Rails version 3.0.0 and my view code is as follows. <% remote_form_for @provider, :url => company_provider_path(@company), :method => :put do |provider_form| %>. In side this form, I am using AJAX call to update the form values and Now I want to pass the same details to another function for validation. I have used the tag '<%= submit_tag "page_level_validation", :id => "page_level_validation" , :action=>"validate"%>' but it also pass the details to the same 'update function' via AJAX. – Sushanth CS Nov 24 '10 at 05:56
  • So the issue is on remote_form_for I am using in rails 3. Then what I should used instead of it? I have already wrote many functionalities inside this form. Is my form changes effects that functionalities also? – Sushanth CS Nov 24 '10 at 06:06

2 Answers2

0

You can't set the submit to point to a different place than the main form has specified (unless you want to use the HTML5 formaction attribute and deal with the browser compatibility consequences).

However, what you could do is create a new action in your controller which deals with the situation.

e.g..

<% remote_form_for @employee, :url => organization_employee_validate_path(@organization, @employee), :method => :put do |employee_form| %>

in your controller

def validate
    #do something loosely based around the update method
end

not forgetting to add the appropriate routes.

Carpela
  • 2,155
  • 1
  • 24
  • 55
-1

Try this:

<% form_for @employee, :remote => true, :url => organization_employee_path(@organization, @employee), :method => :put do |employee_form| %>
clemensp
  • 2,525
  • 23
  • 21