简体   繁体   English

如何在Rails3中将状态设置为活动

[英]How to set status to active in rails3

I am using rails3 and I have a user model. 我正在使用rails3,并且有一个用户模型。 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. 我当时想实现一个发布请求,我应该点击批准或拒绝ajax调用。

In the ajax call I would make post call instead of get. 在ajax调用中,我将进行发布而不是获取。

Is this a good strategy? 这是个好策略吗? Anyone has any better suggestion. 任何人都有更好的建议。

Thanks 谢谢

Just pass :method => 'post' to your link_to call: 只需将:method => 'post'传递给您的link_to调用即可:

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

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

You're right, it shouldn't be a get request. 没错,这不应该是get请求。 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 . 您可以将:method => :put传递给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. Rails将创建一个JS处理程序,并且当单击链接时,它将创建一个带有action=PUT的不可见表单并提交。

BUT, AJAX is a nice thing too and it's just as hard as setting the method: :remote => true 但是,AJAX也是一件好事,就像设置方法一样困难:remote => true

HTTP POST is used for create, and HTTP PUT is used for update. HTTP POST用于创建,HTTP PUT用于更新。 As such, you should be using doing a PUT (add :method => 'put' to your link_to) since you are updating the user record. 因此,由于您正在更新用户记录,因此您应该使用PUT(在link_to中添加:method =>'put')。 Here's more details: http://guides.rubyonrails.org/routing.html#crud-verbs-and-actions 这是更多详细信息: http : //guides.rubyonrails.org/routing.html#crud-verbs-and-actions

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Rails3 Active Admin:首次点击Shipments标签时如何仅显示打开状态记录? - Rails3 Active Admin: How to display only Open status records when first click on Shipments tag? Rails3 对主动关系感到困惑 - Rails3 confused on active relations 如何在Rails3中使用CanCan在活动页面上显示AccessDenied错误 - How to show AccessDenied errors on the active page with CanCan in Rails3 如何在Rails3中的Active Record中按天和年分组 - How to group by day and year in Active Record in Rails3 Rails3:如何根据环境设置应用程序变量 - Rails3: How do I set variables for the app depending on the ENVIRONMENT Rails3:如何将默认条件设置为has_many - Rails3: how to set default conditions to has_many 如何通过Ruby on Rails3中的表单输入设置外键? - How to set foreigns keys through form input in Ruby on Rails3? Rails3:如何设置特定于项目的bash环境变量? - Rails3: How to set bash environment variables that are project-specific? Rails3 / Sessions / Active_Record_Store / Signout - &gt;如何删除会话表中的cookie和记录? - Rails3 / Sessions / Active_Record_Store / Signout --> How to delete the cookie and the record in the Sessions table? Rails3 Active Admin - 如何仅过滤符合集合中所有已检查项目的记录 - Rails3 Active Admin - How to filter only records that meet all checked items in collection
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM