# form\_for url.. how to send data to another controller

**URL:** <https://discuss.rubyonrails.org/t/form-for-url-how-to-send-data-to-another-controller/46730>\
**Category:** rubyonrails-talk\
**Created:** [October 10, 2009, 3:41pm UTC](https://discuss.rubyonrails.org/t/form-for-url-how-to-send-data-to-another-controller/46730 "2009-10-10T15:41:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Erwin1](https://avatars.discourse-cdn.com/v4/letter/e/d07c76/32.png) [@Erwin1](https://discuss.rubyonrails.org/u/Erwin1)\
**Post date:** [October 10, 2009, 3:41pm UTC](https://discuss.rubyonrails.org/t/form-for-url-how-to-send-data-to-another-controller/46730/1 "2009-10-10T15:41:18Z")

</div>

@trainee is an instance of User class

my form partial code :

\<% form\_for :@trainee, :html =\> {:class =\> 'generalform'} do |form| %\> &nbsp;&nbsp;\<%= render :partial =\> "form", :object =\> form %\> &nbsp;&nbsp;&nbsp;\<%= 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 erwin

---

<div class="post-metadata">

**Author:** ![Colin\_Law1](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Colin\_Law1](https://discuss.rubyonrails.org/u/Colin_Law1)\
**Post date:** [October 10, 2009, 4:18pm UTC](https://discuss.rubyonrails.org/t/form-for-url-how-to-send-data-to-another-controller/46730/2 "2009-10-10T16:18:22Z")

</div>

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

Colin

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [October 10, 2009, 6:18pm UTC](https://discuss.rubyonrails.org/t/form-for-url-how-to-send-data-to-another-controller/46730/3 "2009-10-10T18:18:38Z")

</div>

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 \<h1\>Gathering transient data\</h1\> \<% form\_tag('transient/show') do %\>\<!--sends to the show method of the transient controller--\> &nbsp;&nbsp;\<p\> &nbsp;&nbsp;&nbsp;&nbsp;\<b\>First Name\</b\>\<br /\> &nbsp;&nbsp;\<%= text\_field\_tag "firstname", TransientData.firstname %\> &nbsp;&nbsp;\<br/\>\<b\>Last Name\</b\>\<br /\> &nbsp;&nbsp;\<%= text\_field\_tag "lastname", TransientData.lastname %\> &nbsp;&nbsp;\<%= submit\_tag "Submit" %\> &nbsp;&nbsp;\</p\> \<%end%\>

show.html.erb

\<h1\>Gathering transient data\</h1\> \<% form\_tag('/transient/gather') do%\> \<!--and back to gather--\> &nbsp;&nbsp;\<p\> &nbsp;&nbsp;&nbsp;&nbsp;\<b\>First Name\</b\>\<br /\> &nbsp;&nbsp;\<%= TransientData.firstname %\> &nbsp;&nbsp;\<br/\>\<b\>Last Name\</b\>\<br /\> &nbsp;&nbsp;\<%= TransientData.lastname %\> &nbsp;&nbsp;\<%= submit\_tag "Submit" %\> &nbsp;&nbsp;\</p\>

\<%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 Kerforn wrote:

---

<div class="post-metadata">

**Author:** ![Erwin1](https://avatars.discourse-cdn.com/v4/letter/e/d07c76/32.png) [@Erwin1](https://discuss.rubyonrails.org/u/Erwin1)\
**Post date:** [October 11, 2009, 9:07am UTC](https://discuss.rubyonrails.org/t/form-for-url-how-to-send-data-to-another-controller/46730/4 "2009-10-11T09:07:35Z")

</div>

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...

---

<div class="post-metadata">

**Author:** ![Erwin1](https://avatars.discourse-cdn.com/v4/letter/e/d07c76/32.png) [@Erwin1](https://discuss.rubyonrails.org/u/Erwin1)\
**Post date:** [October 11, 2009, 9:10am UTC](https://discuss.rubyonrails.org/t/form-for-url-how-to-send-data-to-another-controller/46730/5 "2009-10-11T09:10:32Z")

</div>

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