开发者

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 r开发者_开发问答equest. 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜