# Calling Create action from a link\_to

**URL:** <https://www.ruby-forum.com/t/calling-create-action-from-a-link-to/149585>\
**Category:** Rails\
**Created:** [September 26, 2008, 3:21pm UTC](https://www.ruby-forum.com/t/calling-create-action-from-a-link-to/149585 "2008-09-26T15:21:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ratcheer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/aca169/32.png) [@ratcheer](https://www.ruby-forum.com/u/ratcheer)\
**Post date:** [September 26, 2008, 3:21pm UTC](https://www.ruby-forum.com/t/calling-create-action-from-a-link-to/149585/1 "2008-09-26T15:21:32Z")

</div>

Hi,  
I have a Collection resource set up and I have configured my routes  
file:  
map.resources :collections

I want to have a link which will create a new collection (instead of  
adding one via the form in the New action). I was under the impression  
that I could just do a POST call to the collections\_path. e.g:  
\<%= link\_to “New Collection”, collections\_path, :method =\> :post %\>

However, when I do this, I am routed to the Index action. The logs  
show:  
Processing CollectionsController#index (for 127.0.0.1 at 2008-09-26  
14:20:22) [POST]  
Session ID: 0b5dd35a6f2133dc7a9840e2d786c822  
Parameters: {“action”=\>“index”,  
“authenticity\_token”=\>“cb5d37816a3a4f0bdc14701b8a5127f1c3dc99c6”,  
“controller”=\>“collections”}

What am I doing wrong? Why is the POST to the collections path routing  
me to the index action? How do I make a link to the create action?

Thanks

---

<div class="post-metadata">

**Author:** ![ratcheer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/aca169/32.png) [@ratcheer](https://www.ruby-forum.com/u/ratcheer)\
**Post date:** [September 26, 2008, 3:35pm UTC](https://www.ruby-forum.com/t/calling-create-action-from-a-link-to/149585/2 "2008-09-26T15:35:13Z")

</div>

On Sep 26, 9:21 pm, Tim C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> However, when I do this, I am routed to the Index action. The logs
> 
> ## Thanks
> 
> Posted viahttp://www.ruby-forum.com/.

The parameter :method should be put on the html options hash instead  
of the url hash. Try this:

\<%= link\_to “New Collection”, {}, :method =\> :post %\>

---

<div class="post-metadata">

**Author:** ![ratcheer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/aca169/32.png) [@ratcheer](https://www.ruby-forum.com/u/ratcheer)\
**Post date:** [September 26, 2008, 4:40pm UTC](https://www.ruby-forum.com/t/calling-create-action-from-a-link-to/149585/3 "2008-09-26T16:40:59Z")

</div>

Apologies, i must not have restarted the server after changing some  
routes. I’ve restarted and its behaving as expected now.  
Thanks for the help

---

<div class="post-metadata">

**Author:** ![ratcheer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/aca169/32.png) [@ratcheer](https://www.ruby-forum.com/u/ratcheer)\
**Post date:** [September 26, 2008, 4:06pm UTC](https://www.ruby-forum.com/t/calling-create-action-from-a-link-to/149585/4 "2008-09-26T16:06:56Z")

</div>

On Sep 26, 8:21 am, Tim C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> However, when I do this, I am routed to the Index action. The logs
> 
> ## Thanks
> 
> Posted viahttp://www.ruby-forum.com/.

That is strange. It should route to the create action.

Any chance you have a route higher up in your routes.rb that’s taking  
precedence?

Also what version of Rails? (perhaps you made a change to your  
routes.rb and need to restart your local server?)

Jeff

REST with Rails: Oct 4, 2008 in Austin TX:  
[http://purpleworkshops.com/workshops/rest-and-web-services](http://purpleworkshops.com/workshops/rest-and-web-services)  
Use discount code “PWRRGG”
