REST link_to and PUT question

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

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 :slight_smile:

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 :slight_smile: