# REST link\_to and PUT question

**URL:** <https://www.ruby-forum.com/t/rest-link-to-and-put-question/116470>\
**Category:** Rails\
**Created:** [October 5, 2007, 8:48pm UTC](https://www.ruby-forum.com/t/rest-link-to-and-put-question/116470 "2007-10-05T20:48:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pallan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/71c47a/32.png) [@pallan](https://www.ruby-forum.com/u/pallan)\
**Post date:** [October 5, 2007, 8:48pm UTC](https://www.ruby-forum.com/t/rest-link-to-and-put-question/116470/1 "2007-10-05T20:48:26Z")

</div>

Hi all,

I am learning how to think RESTfully and in my quest for improvement I  
need help with the issue I am facing.

I have a RESTful model “User” and I want to add a link on the listing  
(index) page that is a one-click to disable/enable that user i.e. simply  
toggle the active column to the correct value. Since I am just updating  
a column in the object it seemed to me that this should be a simple PUT  
request with the correct value for the column (true/false). However, I  
can’t figure out how I can add the value of “active” to the request  
using a link\_to and the REST routes helper methods.

\<%= link\_to ‘Disable’, user\_path(user), :method =\> :put %\>

Is as far as I have been able to get. I did try changing the url to use  
the raw hash but that didn’t work either. Could someone please give me  
some direction on this?

Oh yeah, I do realize I could create a new member route for this, but  
somehow it doesn’t seem “correct” considering it should just be a simple  
Update operation.

Thanks

Peer

---

<div class="post-metadata">

**Author:** ![pallan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/71c47a/32.png) [@pallan](https://www.ruby-forum.com/u/pallan)\
**Post date:** [October 5, 2007, 10:41pm UTC](https://www.ruby-forum.com/t/rest-link-to-and-put-question/116470/2 "2007-10-05T22:41:59Z")

</div>

Peer A. wrote:

> Hi all,
> 
> I am learning how to think RESTfully and in my quest for improvement I  
> need help with the issue I am facing.
> 
> I have a RESTful model “User” and I want to add a link on the listing  
> (index) page that is a one-click to disable/enable that user i.e. simply  
> toggle the active column to the correct value. Since I am just updating  
> a column in the object it seemed to me that this should be a simple PUT  
> request with the correct value for the column (true/false). However, I  
> can’t figure out how I can add the value of “active” to the request  
> using a link\_to and the REST routes helper methods.
> 
> \<%= link\_to ‘Disable’, user\_path(user), :method =\> :put %\>
> 
> Is as far as I have been able to get. I did try changing the url to use  
> the raw hash but that didn’t work either. Could someone please give me  
> some direction on this?
> 
> Oh yeah, I do realize I could create a new member route for this, but  
> somehow it doesn’t seem “correct” considering it should just be a simple  
> Update operation.
> 
> Thanks
> 
> Peer

Try:

\<%= link\_to ‘Disable’, user\_path(:id =\> user.id, :active =\> false),  
:method =\> :put %\>

Yeah, it’s ugly, but it should work. I had a similar problem, and had to  
resort to this as well. If someone knows a better solution, please let  
me know 🙂

---

<div class="post-metadata">

**Author:** ![pallan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/71c47a/32.png) [@pallan](https://www.ruby-forum.com/u/pallan)\
**Post date:** [October 5, 2007, 10:55pm UTC](https://www.ruby-forum.com/t/rest-link-to-and-put-question/116470/3 "2007-10-05T22:55:29Z")

</div>

Thanks for the response, but unfortunately that did not work. I looked  
at the javascript generated by and there is no reference of the “active”  
field and naturally it is not part of the params when I submit.

Peer

Gerjan S. wrote:

> Try:
> 
> \<%= link\_to ‘Disable’, user\_path(:id =\> user.id, :active =\> false),  
> :method =\> :put %\>
> 
> Yeah, it’s ugly, but it should work. I had a similar problem, and had to  
> resort to this as well. If someone knows a better solution, please let  
> me know 🙂
