# Use of button\_to to access action "new"

**URL:** <https://www.ruby-forum.com/t/use-of-button-to-to-access-action-new/151103>\
**Category:** Rails\
**Created:** [October 16, 2008, 8:48pm UTC](https://www.ruby-forum.com/t/use-of-button-to-to-access-action-new/151103 "2008-10-16T20:48:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![markmt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/df705f/32.png) [@markmt](https://www.ruby-forum.com/u/markmt)\
**Post date:** [October 16, 2008, 8:48pm UTC](https://www.ruby-forum.com/t/use-of-button-to-to-access-action-new/151103/1 "2008-10-16T20:48:18Z")

</div>

I have a question about what is regarded as good practice in the  
context of RESTful Rails interfaces.

I have a Subscribers Controller with “index” and “new” (and other)  
actions. In routes.rb I define resource-based routing with  
“map.resources :subscribers”.

In my index view I have a button\_to that points to  
“new\_subscriber\_path”. Since the button generates a POST request,  
which doesn’t match any resource-based routes, I also have  
“map.connect ‘:controller/:action’” in routes.rb to ensure that the  
request goes to the intended "new"action.

This does exactly what I want it to, but it seems a little awkward to  
have defined RESTful routes, and in this particular case to not use  
one because of a UI design choice I’ve made (a button instead of a  
link). Should this be viewed as a limitation in the way Rails supports  
REST, or is there a different way I should be doing this?

Mark.

---

<div class="post-metadata">

**Author:** ![markmt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/df705f/32.png) [@markmt](https://www.ruby-forum.com/u/markmt)\
**Post date:** [October 16, 2008, 10:24pm UTC](https://www.ruby-forum.com/t/use-of-button-to-to-access-action-new/151103/2 "2008-10-16T22:24:28Z")

</div>

MarkMT wrote:

> In my index view I have a button\_to that points to  
> “new\_subscriber\_path”. Since the button generates a POST request,  
> which doesn’t match any resource-based routes, I also have  
> “map.connect ‘:controller/:action’” in routes.rb to ensure that the  
> request goes to the intended "new"action.

button\_to creates a form, and forms can GET. That is in fact what forms  
do by default, but rails specifies that they should be POST because  
that’s what most people probably want. Anyway, button\_to “Foo”,  
bar\_path, :method =\> :get is the way to go, rather than adding routes  
like that.

---

<div class="post-metadata">

**Author:** ![markmt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/df705f/32.png) [@markmt](https://www.ruby-forum.com/u/markmt)\
**Post date:** [October 16, 2008, 11:19pm UTC](https://www.ruby-forum.com/t/use-of-button-to-to-access-action-new/151103/3 "2008-10-16T23:19:18Z")

</div>

Thank you! Just what I needed to know!

Mark.

On Oct 16, 3:24 pm, August L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
