# Returning to multiple controllers from a single view.

**URL:** <https://discuss.rubyonrails.org/t/returning-to-multiple-controllers-from-a-single-view/28730>\
**Category:** rubyonrails-talk\
**Created:** [April 29, 2008, 6:20pm UTC](https://discuss.rubyonrails.org/t/returning-to-multiple-controllers-from-a-single-view/28730 "2008-04-29T18:20:29Z")\
**Posts on this page:** 17\
**Page:** 1

<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:** [April 29, 2008, 6:20pm UTC](https://discuss.rubyonrails.org/t/returning-to-multiple-controllers-from-a-single-view/28730/1 "2008-04-29T18:20:29Z")

</div>

Given:

class Entity

has\_one :client

class Client

belongs\_to :entity

I have the situation where a client role either can be created coincidentally with an entity or subsequent to an entity's creation. I have therefore created two controllers to handle this within the constraints of ReST: clients\_controller, which handles the coincidental creation situation; and entity\_clients\_controller, which handles the case of adding a client role to an existing entity.

Now it seems desirable that I use the same view to do this since the user input fields are exactly the same in both cases. The only difference being is that in the latter case the entity values are already provided. So, inside entity\_clients\_controller I have this code:

def new &nbsp;&nbsp;@entity = Entity.find(params[:entity\_id]) &nbsp;&nbsp;@client = @entity.build\_client &nbsp;&nbsp;@client.effective\_from = Time.now.to\_date

&nbsp;&nbsp;respond\_to do |format| &nbsp;&nbsp;&nbsp;&nbsp;format.html { render :template =\> 'clients/new' } # new.html.erb &nbsp;&nbsp;&nbsp;&nbsp;format.xml { render :xml =\> @client } &nbsp;&nbsp;end end

Which displays the contents of the passed entity in the fields of the new template. Everything works up to this point. My problem is that the submit button on the clients/new view redirects back to clients\_controller or course. However, clients\_controller expects to create a new entity as well as a client and that simply will not do.

My question is therefore, how do I handle this? I want a single view, called from two controllers, to return to the calling controller. How is this properly done in Rails? Do I really need a separate view?

---

<div class="post-metadata">

**Author:** ![Roger\_Pack](https://avatars.discourse-cdn.com/v4/letter/r/50afbb/32.png) [@Roger\_Pack](https://discuss.rubyonrails.org/u/Roger_Pack)\
**Post date:** [April 29, 2008, 6:58pm UTC](https://discuss.rubyonrails.org/t/returning-to-multiple-controllers-from-a-single-view/28730/2 "2008-04-29T18:58:59Z")

</div>

typically I use an if statement on params[:controller] or params[:action] to setup the form so it posts back to the right place. [?]

---

<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:** [April 29, 2008, 8:58pm UTC](https://discuss.rubyonrails.org/t/returning-to-multiple-controllers-from-a-single-view/28730/3 "2008-04-29T20:58:19Z")

</div>

Roger Pack wrote:

> typically I use an if statement on params[:controller] or params[:action] to setup the form so it posts back to the right place. [?]
> 
> On Tue, Apr 29, 2008 at 12:20 PM, James Byrne

Ahh. I see. In params I have:

--- !map:HashWithIndifferentAccess user: !map:HashWithIndifferentAccess &nbsp;&nbsp;userid: authuser &nbsp;&nbsp;user\_id: 13466 &nbsp;&nbsp;user\_name: A. N. Authorized-User entity\_id: "1" action: new controller: entity\_client

form\_helper.submit simply calls submit\_tag with these parameters:

def submit(value = "Save changes", options = {}) &nbsp;&nbsp;&nbsp;@template.submit\_tag(value, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;options.reverse\_merge(:id =\> "#{object\_name}\_submit")) end

which I infer threads back through form\_tag\_helper.rb

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def submit\_tag(value = "Save changes", options = {}) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;options.stringify\_keys!

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if disable\_with = options.delete("disable\_with") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;options["onclick"] = [&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"this.setAttribute('originalValue', this.value)", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"this.disabled=true", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"this.value='#{disable\_with}'", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"#{options["onclick"]}", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit())", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"if (result == false) { this.value = this.getAttribute('originalValue'); this.disabled = false }", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"return result;", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;].join(";") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if confirm = options.delete("confirm") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;options["onclick"] ||= '' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;options["onclick"] += "return #{confirm\_javascript\_function(confirm)};" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tag :input, { "type" =\> "submit", "name" =\> "commit", "value" =\> value }.update(options.stringify\_keys) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

But I cannot see where the magic that determines what controller gets to handle the request happens. Can someone with far greater familiarity with the Rails internals point me in the right direction?

It seems to me at first blush that given that the calling controller is passed to a view that it should be possible, indeed even a desirable default, that control should return to the calling controller rather than to one derived from the view/object name, or am I missing something significant?

In any case, it might be useful to have an option for the submit method to pass the controller name as an argument :controller =\> params[:controller] for instance.

---

<div class="post-metadata">

**Author:** ![Roger\_Pack](https://avatars.discourse-cdn.com/v4/letter/r/50afbb/32.png) [@Roger\_Pack](https://discuss.rubyonrails.org/u/Roger_Pack)\
**Post date:** [April 29, 2008, 9:13pm UTC](https://discuss.rubyonrails.org/t/returning-to-multiple-controllers-from-a-single-view/28730/4 "2008-04-29T21:13:00Z")

</div>

with link\_to [or form\_for or whatever] if you don't specify a controller as a parameter, it defaults to the current controller [and the calling action is also the default]. -R

---

<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:** [April 30, 2008, 1:30pm UTC](https://discuss.rubyonrails.org/t/returning-to-multiple-controllers-from-a-single-view/28730/5 "2008-04-30T13:30:56Z")

</div>

> I am starting with a form\_for block in the view which has a submit method at the end. Is the recommended solution for my proplem to take out the submit and replace it with a link\_to method?

a bit clarification: there are several methods to call a controller action:

most simple: link\_to "text", url

with data: form\_tag url &nbsp;&nbsp;fields &nbsp;&nbsp;submit\_tag end

and a few more. but in any case you have to give it an url as an option and you can chose that url to point wherever you want. you can make this decision static or variable.

but in case of using a form the submit button has nothing to do with the controller, action or url, that's defined in the form\_tag (or form\_for or whatever kind you use)

maybe you just post your view code

---

<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:** [April 30, 2008, 2:07pm UTC](https://discuss.rubyonrails.org/t/returning-to-multiple-controllers-from-a-single-view/28730/6 "2008-04-30T14:07:56Z")

</div>

Thorsten Mueller wrote:

> maybe you just post your view code

The entire view: ---\> \<%- content\_tag\_for :h2, @client, :heading do %\> &nbsp;&nbsp;Adding Client Role for Entity &nbsp;&nbsp;\<%#= @client.entity.id.to\_s -%\> &nbsp;&nbsp;\<%- end -%\>

\<%= error\_messages\_for :client -%\> \<%= error\_messages\_for :entity -%\>

\<%- form\_for(@client) do |f| -%\>

&nbsp;&nbsp;\<%= render :partial =\> 'entities/entity\_header', &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:object =\> @entity -%\>

&nbsp;&nbsp;\<%= render :partial =\> 'clients/client\_detail', &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:object =\> @client -%\>

&nbsp;&nbsp;\<%= render :partial =\> 'shared/effective\_period', &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:object =\> @client -%\>

&nbsp;&nbsp;\<p\> &nbsp;&nbsp;&nbsp;&nbsp;\<%= f.submit "Create" -%\> &nbsp;&nbsp;\</p\> \<%- end -%\>

\<%= link\_to 'Back', clients\_path -%\>

\<br /\>

\<!-- Disable debug in production --\> &nbsp;&nbsp;\<%= &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;debug(params).to\_yaml &nbsp;&nbsp;-%\> \<---

This view is called from two controllers, clients\_controller and entity\_clients\_controller. In the first instance (clients) the entity does not, or should not, exist. In the second case (entity\_clients\_controller), the entity is known to exist and the client role is to be added.

On the submit action (create == post?) control is sent to the clients controller regardless of origin. I simply wish to send control back to the calling controller.

---

<div class="post-metadata">

**Author:** ![Roger\_Pack](https://avatars.discourse-cdn.com/v4/letter/r/50afbb/32.png) [@Roger\_Pack](https://discuss.rubyonrails.org/u/Roger_Pack)\
**Post date:** [April 30, 2008, 2:56pm UTC](https://discuss.rubyonrails.org/t/returning-to-multiple-controllers-from-a-single-view/28730/7 "2008-04-30T14:56:53Z")

</div>

double check the parameters for form\_for [?]

---

<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:** [April 30, 2008, 3:24pm UTC](https://discuss.rubyonrails.org/t/returning-to-multiple-controllers-from-a-single-view/28730/8 "2008-04-30T15:24:16Z")

</div>

Roger Pack wrote:

> double check the parameters for form\_for [?]

I am afraid that I lack the experience to express my desire to dynamically determine the controller context in the form\_to options. Is there an opotion to specify :controller =\> params[:controller] ?. If so then I cannot see it.

---

<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:** [April 30, 2008, 3:30pm UTC](https://discuss.rubyonrails.org/t/returning-to-multiple-controllers-from-a-single-view/28730/9 "2008-04-30T15:30:47Z")

</div>

ok, you're using the shortcut version

form\_for(@client)

here. this can take a lot of additiional parameters. from what u use, rails will generate the following defaults:

form\_for :client, @client, :url =\> client\_path(@client), :html =\> { :method =\> :put, :class =\> "edit\_client", :id =\> "edit\_client\_45" }

if @client is an existing record or if it's a new one it would be:

form\_for :client, @client, :url =\> clients\_path, :html =\> { :class =\> "new\_client", :id =\> "new\_client" }

so if you want to change details, just overwrite the right parameter like: (assuming @has\_entity \<% if @entity then %\> \<%= form\_for(@client, :url =\> client\_path(@client)) \<% else %\> \<%= form\_for(@client, :url =\> entity\_client\_path(@client)) \<% end %\>

or shorter: \<%= form\_for(@client, :url =\> (@entity ? client\_path(@client) : entity\_client\_path(@client)))

there are some more options to handle this, depending if you always have the Client in your db or may have to handle both new/create and edit/update

[http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#M000920](http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#M000920)

---

<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:** [April 30, 2008, 3:48pm UTC](https://discuss.rubyonrails.org/t/returning-to-multiple-controllers-from-a-single-view/28730/10 "2008-04-30T15:48:31Z")

</div>

Thorsten Mueller wrote:

> or shorter: \<%= form\_for(@client, :url =\> (@entity ? client\_path(@client) : entity\_client\_path(@client)))

If I understand then this code means that if @entity is not nil, in other words this view was called from entity\_clients\_controller, then the form submit action will return to client\_path but if @entity is nil then control returns to entity\_client\_path. Is this correct?

If this is so then I get the idea but the behaviour of the example is reversed from what I desire. @entity is nil when called from clients\_controller so that the construct that I believe I should use is:

\<%= form\_for(@client, :url =\> (@entity ? entity\_client\_path(@client) :

> client\_path(@client)))

Is this correct?

---

<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:** [April 30, 2008, 4:22pm UTC](https://discuss.rubyonrails.org/t/returning-to-multiple-controllers-from-a-single-view/28730/11 "2008-04-30T16:22:50Z")

</div>

right you simply overwrite default behaviour by providing the url explicitly you can make this depend onwhatever you want, the existing of an @entity in your case or the controller name

(and yes, i got it the wrong way around)

---

<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:** [April 30, 2008, 5:21pm UTC](https://discuss.rubyonrails.org/t/returning-to-multiple-controllers-from-a-single-view/28730/12 "2008-04-30T17:21:11Z")

</div>

James Byrne wrote:

After (re)wrapping my head around the x ? T : F construct (which I read is gone from Ruby 1.9) I did this:

\<%- form\_for(@client, \ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:url =\> (@entity ? client\_path(@client) \ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: entity\_client\_path(@client))) do |f| -%\>

This works fine for the original call from the client controller. New clients and their associated entities are created in one go as was formerly the case.

However, with the call to add a client from entities/index:

\<%- if entity.client.nil? -%\> &nbsp;&nbsp;\<%= link\_to 'Add Client Role', new\_entity\_client\_path(entity) -%\> \<%- else -%\>

I go to:

[http://localhost:3000/entities/1/client/new](http://localhost:3000/entities/1/client/new)

and then I see this (in addition to the client/new view fields:

--- !map:HashWithIndifferentAccess user: !map:HashWithIndifferentAccess &nbsp;&nbsp;userid: authuser &nbsp;&nbsp;user\_id: 13466 &nbsp;&nbsp;user\_name: A. N. Authorized-User entity\_id: "1" action: new controller: entity\_client

Named Routes for entity\_client Name &nbsp;&nbsp;Requirements &nbsp;&nbsp;Conditions formatted\_entity\_client &nbsp;&nbsp;{:controller=\>"entity\_client", :action=\>"show"} &nbsp;&nbsp;{:method=\>:get}

entity\_client &nbsp;&nbsp;{:controller=\>"entity\_client", :action=\>"show"} &nbsp;&nbsp;{:method=\>:get}

formatted\_edit\_entity\_client &nbsp;&nbsp;{:controller=\>"entity\_client", :action=\>"edit"} &nbsp;&nbsp;{:method=\>:get}

edit\_entity\_client &nbsp;&nbsp;{:controller=\>"entity\_client", :action=\>"edit"} &nbsp;&nbsp;{:method=\>:get}

formatted\_new\_entity\_client &nbsp;&nbsp;{:controller=\>"entity\_client", :action=\>"new"} &nbsp;&nbsp;{:method=\>:get}

new\_entity\_client &nbsp;&nbsp;{:controller=\>"entity\_client", :action=\>"new"} &nbsp;&nbsp;{:method=\>:get}

Where am I going to when I submit in this case? I end up with the same error as above.

---

<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:** [April 30, 2008, 5:31pm UTC](https://discuss.rubyonrails.org/t/returning-to-multiple-controllers-from-a-single-view/28730/13 "2008-04-30T17:31:03Z")

</div>

James Byrne wrote:

> James Byrne wrote:

> &nbsp;&nbsp;\<%= link\_to 'Add Client Role', new\_entity\_client\_path(entity) -%\>

> and then I see this (in addition to the client/new view fields:
> 
> --- !map:HashWithIndifferentAccess user: !map:HashWithIndifferentAccess &nbsp;&nbsp;userid: authuser &nbsp;&nbsp;user\_id: 13466 &nbsp;&nbsp;user\_name: A. N. Authorized-User entity\_id: "1" action: new controller: entity\_client

the new action does not need an id, so it's path helper does not allow one by default. (depending on the kind of action and your routing, rails expects one or more default ids and accepts simple values for them. additional parameters must be defined with a params key)

use: \<%= link\_to 'Add Client Role', new\_entity\_client\_path(:entity\_id =\> entity) -%\>

instead. this will return as params[:entity\_id]. the name of the key can be changed if you want to. it's entity that generated that error, since rails wanted to treat it as the hash :params\_key =\> id

---

<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:** [April 30, 2008, 5:45pm UTC](https://discuss.rubyonrails.org/t/returning-to-multiple-controllers-from-a-single-view/28730/14 "2008-04-30T17:45:57Z")

</div>

Thorsten Mueller wrote:

> use: \<%= link\_to 'Add Client Role', new\_entity\_client\_path(:entity\_id =\> entity) -%\>
> 
> instead. this will return as params[:entity\_id]. the name of the key can be changed if you want to. it's entity that generated that error, since rails wanted to treat it as the hash :params\_key =\> id

Please bear with me, I am very unfamiliar with all this.

What I have now is this:

clients/new

\<%- form\_for(@client, \ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:url =\> (@entity ? client\_path(@client) \ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: entity\_client\_path(@client))) do |f| -%\>

&nbsp;&nbsp;\<%= render :partial =\> 'entities/entity\_header', &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:object =\> @entity -%\>

&nbsp;&nbsp;\<%= render :partial =\> 'clients/client\_detail', &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:object =\> @client -%\>

&nbsp;&nbsp;\<%= render :partial =\> 'shared/effective\_period', &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:object =\> @client -%\>

&nbsp;&nbsp;\<p\> &nbsp;&nbsp;&nbsp;&nbsp;\<%= f.submit "Create" -%\> &nbsp;&nbsp;\</p\> \<%- end -%\>

Am I to remove \<%= f.submit "Create" -%\>

and replace it with

\<%= link\_to 'Add Client Role', etc.?

keeping the rest the same?

The error I am getting is a validations check that the entity already exists. That is the correct behaviour when adding a client and an entity together as the entity should not already be on file. However, in the case where the entity is known to exist beforehand I do not want the validation to fail. Is this really a problem in the way I imagine validations to work?

I thought that the problem arose because in the clients controller the code to add the client role looks like this:

&nbsp;&nbsp;def create &nbsp;&nbsp;&nbsp;&nbsp;@entity = Entity.new(params[:entity])

&nbsp;&nbsp;&nbsp;&nbsp;# need this to strip out observer attributes for datebalks plugin &nbsp;&nbsp;&nbsp;&nbsp;# see config/initializers/hash\_addins.rb

&nbsp;&nbsp;&nbsp;&nbsp;@client = @entity.build\_client(params[:client].datebalk!)

&nbsp;&nbsp;&nbsp;&nbsp;respond\_to do |format| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if @entity.save &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flash[:notice] = 'Client was successfully created.' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;format.html { redirect\_to(@client) } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;format.xml { render :xml =\> @client, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:status =\> :created, :location =\> @client } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;format.html { render :action =\> "new" } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;format.xml { render :xml =\> @client.errors, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:status =\> :unprocessable\_entity } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

but in entity\_client\_controller it looks like this:

def create &nbsp;&nbsp;@entity = Entity.find(params[:entity\_id])

&nbsp;&nbsp;# need this to strip out observer attributes for datebalks plugin &nbsp;&nbsp;# see config/initializers/hash\_addins.rb

&nbsp;&nbsp;@client = @entity.build\_client(params[:client].datebalk!)

&nbsp;&nbsp;respond\_to do |format| &nbsp;&nbsp;&nbsp;&nbsp;if @client.save &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flash[:notice] = 'Client was successfully created.' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;format.html { redirect\_to(@client) } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;format.xml { render :xml =\> @client, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:status =\> :created, :location =\> @client } &nbsp;&nbsp;&nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;format.html { render :action =\> "new" } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;format.xml { render :xml =\> @client.errors, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:status =\> :unprocessable\_entity } &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;end end

I surmise that I may have something amiss in the controller?

---

<div class="post-metadata">

**Author:** ![Roger\_Pack](https://avatars.discourse-cdn.com/v4/letter/r/50afbb/32.png) [@Roger\_Pack](https://discuss.rubyonrails.org/u/Roger_Pack)\
**Post date:** [April 30, 2008, 9:52pm UTC](https://discuss.rubyonrails.org/t/returning-to-multiple-controllers-from-a-single-view/28730/15 "2008-04-30T21:52:31Z")

</div>

[http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html](http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html) form\_for can have parameters &nbsp;&nbsp;&nbsp;&nbsp;\<% form\_for :person, @person, :url =\> { :action =\> "create", :controller =\> 'controller\_y' } do |f| %\> ...

---

<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:** [May 1, 2008, 2:39pm UTC](https://discuss.rubyonrails.org/t/returning-to-multiple-controllers-from-a-single-view/28730/16 "2008-05-01T14:39:08Z")

</div>

Roger Pack wrote:

> [ActionView::Helpers::FormHelper](http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html) form\_for can have parameters &nbsp;&nbsp;&nbsp;&nbsp;\<% form\_for :person, @person, :url =\> { :action =\> "create", :controller =\> 'controller\_y' } do |f| %\> ...
> 
> On Wed, Apr 30, 2008 at 11:45 AM, James Byrne

This is exactly what I was trying to discover. Thank you very much for all the help. This is what I ended up with in the view:

\<%- form\_for @client, :url =\> { :action =\> 'create', \ &nbsp;&nbsp;&nbsp;&nbsp;:controller =\> "#{params[:controller]}" } do |f| -%\>

---

<div class="post-metadata">

**Author:** ![Roger\_Pack](https://avatars.discourse-cdn.com/v4/letter/r/50afbb/32.png) [@Roger\_Pack](https://discuss.rubyonrails.org/u/Roger_Pack)\
**Post date:** [May 1, 2008, 8:20pm UTC](https://discuss.rubyonrails.org/t/returning-to-multiple-controllers-from-a-single-view/28730/17 "2008-05-01T20:20:19Z")

</div>

nice work. -R
