简体   繁体   中英

How to set status to active in rails3

I am using rails3 and I have a user model. This model has a status column. I am showing admin following table

Mary approve reject
John approve reject

Both approve and reject are links. Since clicking on approve will approve user's record it should not be a get request. It should be a post request. I was thinking to achieve a post request I should make clicking on approve or reject an ajax call.

In the ajax call I would make post call instead of get.

Is this a good strategy? Anyone has any better suggestion.

Thanks

Just pass :method => 'post' to your link_to call:

<%= link_to 'approve', approve_user_path(user), :method => 'post' %>

http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to

You're right, it shouldn't be a get request. Actually, I think it's neither a post request, because you already have the record and want to change it.

You could just pass :method => :put to link_to . Rails will make a JS handler and when the link is clicked, it will create an invisible form with action=PUT and submit it.

BUT, AJAX is a nice thing too and it's just as hard as setting the method: :remote => true

HTTP POST is used for create, and HTTP PUT is used for update. As such, you should be using doing a PUT (add :method => 'put' to your link_to) since you are updating the user record. Here's more details: http://guides.rubyonrails.org/routing.html#crud-verbs-and-actions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM