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’ %> <%= link_to
‘Cancel’, trainees_path %>
<% end %>

the generated html is obviously :

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
erwin

2009/10/10 Erwin [email protected]:

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

Colin

Erwin,

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:

gather.html.erb

Gathering transient data

<% form_tag('transient/show') do %>

First Name
<%= text_field_tag "firstname", TransientData.firstname %>
Last Name
<%= text_field_tag "lastname", TransientData.lastname %> <%= submit_tag "Submit" %>

<%end%>

show.html.erb

Gathering transient data

<% form_tag('/transient/gather') do%>

First Name
<%= TransientData.firstname %>
Last Name
<%= TransientData.lastname %> <%= submit_tag "Submit" %>

<%end%>

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.

Cris

Kad K. wrote:

@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’ %> <%= link_to
‘Cancel’, trainees_path %>
<% end %>

the generated html is obviously :

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
erwin

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 ;-)))

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/
update

@tutor being a User instance…