form_for url.. how to send data to another controller

@trainee is an instance of User class

my form partial code :

<% form_for :@trainee, :html => {:class => 'generalform'} do |form| %>
  <%= render :partial => "form", :object => form %>
   <%= form.submit "Register", :class => 'go' %>&nbsp;<%= link_to
'Cancel', trainees_path %>
<% end %>

the generated html is obviously :
<form id="new_user" class="generalform" method="post" action="/users">

but I would like to send it to a trainee_controller (rather than to
user_controller... )

(don't want to subclass, I am using roles, and a trainee is a user
with 'trainee' role

is it possible ?if yes, how should I proceed ?

many thanks ba

Have a look at the docs for form_for, the :url option will let you do this.



If I understand what you are trying to do then I was trying to solve a
similar but lesser problem. How to send form data from one method in a
controller to another method in the same controller Iit does seem to
work for your case though). Here is a sample erb:

<h1>Gathering transient data</h1>
<% form_tag('transient/show') do %><!--sends to the show method of the
transient controller-->
    <b>First Name</b><br />
  <%= text_field_tag "firstname", TransientData.firstname %>
  <br/><b>Last Name</b><br />
  <%= text_field_tag "lastname", TransientData.lastname %>
  <%= submit_tag "Submit" %>


<h1>Gathering transient data</h1>
<% form_tag('/transient/gather') do%> <!--and back to gather-->
    <b>First Name</b><br />
  <%= TransientData.firstname %>
  <br/><b>Last Name</b><br />
  <%= TransientData.lastname %>
  <%= submit_tag "Submit" %>


If I change either erb file's line:

<% form_tag('/someothermodel/somemethod')

It did swap form data between controllers.

I hope I understood your question. I am new to ruby.


Kad Kerforn wrote:

Thanks Colin... I looked into it in parallel ... not obvious but I
found the solution (many tries.. as it's not the 'standard' way.. but
I'm just writing a quick app draft)

<% form_for :tutor, @tutor, :url => { :action => "create" } ....
for new/create records

<% form_for :tutor, @tutor, :url => tutor_path(@tutor), .. for edit/

@tutor being a User instance...

thanks .. got it.. see my answer to Colin.... the doc info is not
obvious... I had to read between lines and test test test ...many
different options to watch the generated html.... but it works
well now... ( I keep the 'recipe' in my NoteTaker ;-)))