# Submit form action-\> index, from layout

**URL:** <https://www.ruby-forum.com/t/submit-form-action-index-from-layout/141705>\
**Category:** Rails\
**Created:** [June 29, 2008, 8:38pm UTC](https://www.ruby-forum.com/t/submit-form-action-index-from-layout/141705 "2008-06-29T20:38:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sachinkale](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@sachinkale](https://www.ruby-forum.com/u/sachinkale)\
**Post date:** [June 29, 2008, 8:38pm UTC](https://www.ruby-forum.com/t/submit-form-action-index-from-layout/141705/1 "2008-06-29T20:38:13Z")

</div>

I have a select option tag common to all pages,  
following is the code which I have put in partial, rendered it in  
layout.

\<% form\_tag :action =\> “index” do -%\>  
\<%= select\_tag( “state” ,  
"State 1

State 2 State 3 State 4 Feature Article", :onchange =\> "this.form.submit()") %\> \<% end -%\>
## On form submit, following is the o/p -

Unknown action

## No action responded to create

I need the select option value in the index method, will then select  
appropriate state and request the state from database.

I am newbie, please help me out!

Thanks.

---

<div class="post-metadata">

**Author:** ![sachinkale](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@sachinkale](https://www.ruby-forum.com/u/sachinkale)\
**Post date:** [June 30, 2008, 12:01pm UTC](https://www.ruby-forum.com/t/submit-form-action-index-from-layout/141705/2 "2008-06-30T12:01:17Z")

</div>

Sachin K. wrote:

> I have a select option tag common to all pages,  
> following is the code which I have put in partial, rendered it in  
> layout.
> 
> \<% form\_tag :action =\> “index” do -%\>  
> \<%= select\_tag( “state” ,  
> "State 1
> 
> State 2 State 3 State 4 Feature Article", :onchange =\> "this.form.submit()") %\> \<% end -%\>
> ## On form submit, following is the o/p -
> 
> Unknown action
> 
> ## No action responded to create
> 
> I need the select option value in the index method, will then select  
> appropriate state and request the state from database.
> 
> I am newbie, please help me out!
> 
> Thanks.

Since you are telling that this form is in all your pages, maybe you  
forgot to add the controller name supposed to handle this request.  
Otherwise, the request is send to the controller related to your current  
view while displaying this form.

Try to update your partial with “my\_controller\_name” changed to the good  
one.

\<% form\_tag :controller =\> “my\_controller\_name”, :action =\> “index” do  
-%\>

Then, in your controller, your state value will be accessible through

def index  
state\_value = params[:state]  
end

Guillaume Petit

---

<div class="post-metadata">

**Author:** ![sachinkale](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@sachinkale](https://www.ruby-forum.com/u/sachinkale)\
**Post date:** [June 30, 2008, 2:01pm UTC](https://www.ruby-forum.com/t/submit-form-action-index-from-layout/141705/3 "2008-06-30T14:01:41Z")

</div>

Guillaume Petit wrote:

> Sachin K. wrote:
> 
> > I have a select option tag common to all pages,  
> > following is the code which I have put in partial, rendered it in  
> > layout.
> > 
> > \<% form\_tag :action =\> “index” do -%\>  
> > \<%= select\_tag( “state” ,  
> > "State 1
> > 
> > State 2 State 3 State 4 Feature Article", :onchange =\> "this.form.submit()") %\> \<% end -%\>
> > ## On form submit, following is the o/p -
> > 
> > Unknown action
> > 
> > ## No action responded to create
> > 
> > I need the select option value in the index method, will then select  
> > appropriate state and request the state from database.
> > 
> > I am newbie, please help me out!
> > 
> > Thanks.
> 
> Since you are telling that this form is in all your pages, maybe you  
> forgot to add the controller name supposed to handle this request.  
> Otherwise, the request is send to the controller related to your current  
> view while displaying this form.
> 
> Try to update your partial with “my\_controller\_name” changed to the good  
> one.
> 
> \<% form\_tag :controller =\> “my\_controller\_name”, :action =\> “index” do  
> -%\>
> 
> Then, in your controller, your state value will be accessible through
> 
> def index  
> state\_value = params[:state]  
> end
> 
> Guillaume Petit

Thanks Guillaume for your response.

I need to have the form submit to controller which displays the form.

This form is common to all controllers so I dont want any controller  
name, when no name is specified it picks the intended controller (i.e  
the current page) but does not understands the -\> :action = ‘index’.

I tried what you suggested by manually writing the controller name, but  
the result was same, it does not get the action ‘index’.

I even tried :action =\> controller.action\_name , which is the index  
action, but it did not worked.

I have to use the workaround -

def updatestate  
state\_value = params[:state]  
redirect\_to :action =\> “index”  
end

Thanks Again for your help:)

---

<div class="post-metadata">

**Author:** ![sachinkale](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@sachinkale](https://www.ruby-forum.com/u/sachinkale)\
**Post date:** [July 1, 2008, 3:32pm UTC](https://www.ruby-forum.com/t/submit-form-action-index-from-layout/141705/4 "2008-07-01T15:32:02Z")

</div>

Sachin,  
Would you mind embellishing this topic with a little code from your  
application. I find it could be a wonderful way to work around having  
to use an observe\_field.  
Thank you,  
Kathleen

On Jun 30, 3:32 pm, Sachin K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![sachinkale](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@sachinkale](https://www.ruby-forum.com/u/sachinkale)\
**Post date:** [June 30, 2008, 11:32pm UTC](https://www.ruby-forum.com/t/submit-form-action-index-from-layout/141705/5 "2008-06-30T23:32:21Z")

</div>

Sachin K. wrote:

> Guillaume Petit wrote:
> 
> > Sachin K. wrote:
> > 
> > > I have a select option tag common to all pages,  
> > > following is the code which I have put in partial, rendered it in  
> > > layout.
> > > 
> > > \<% form\_tag :action =\> “index” do -%\>  
> > > \<%= select\_tag( “state” ,  
> > > "State 1
> > > 
> > > State 2 State 3 State 4 Feature Article", :onchange =\> "this.form.submit()") %\> \<% end -%\>
> > > ## On form submit, following is the o/p -
> > > 
> > > Unknown action
> > > 
> > > ## No action responded to create
> > > 
> > > I need the select option value in the index method, will then select  
> > > appropriate state and request the state from database.
> > > 
> > > I am newbie, please help me out!
> > > 
> > > Thanks.
> > 
> > Since you are telling that this form is in all your pages, maybe you  
> > forgot to add the controller name supposed to handle this request.  
> > Otherwise, the request is send to the controller related to your current  
> > view while displaying this form.
> > 
> > Try to update your partial with “my\_controller\_name” changed to the good  
> > one.
> > 
> > \<% form\_tag :controller =\> “my\_controller\_name”, :action =\> “index” do  
> > -%\>
> > 
> > Then, in your controller, your state value will be accessible through
> > 
> > def index  
> > state\_value = params[:state]  
> > end
> > 
> > Guillaume Petit
> 
> Thanks Guillaume for your response.
> 
> I need to have the form submit to controller which displays the form.
> 
> This form is common to all controllers so I dont want any controller  
> name, when no name is specified it picks the intended controller (i.e  
> the current page) but does not understands the -\> :action = ‘index’.
> 
> I tried what you suggested by manually writing the controller name, but  
> the result was same, it does not get the action ‘index’.
> 
> I even tried :action =\> controller.action\_name , which is the index  
> action, but it did not worked.
> 
> I have to use the workaround -
> 
> def updatestate  
> state\_value = params[:state]  
> redirect\_to :action =\> “index”  
> end
> 
> Thanks Again for your help:)

I figured out the solution to my problem of calling form - \> action  
index from a layout in =\> railcast#37 - simple search

I was using ‘post’ method, plus another mistake was appropriate  
controller name…

Following will call the index method of the controller that invokes the  
layout

\<% form\_tag controller.controller\_path, :method =\> ‘get’ do %\>  
\<%= select\_tag(“state”, “ab”  
,:onchange =\> “this.form.submit()”) %\>  
\<% end -%\>

Thanks For help!
