【发布时间】:2015-02-06 00:52:24
【问题描述】:
我在 if else 方法中有 2 个按钮,第一个按钮假设允许用户将布尔值从 false 更改为 true。然后,如果模型显示它是真的,它将显示另一个按钮,即删除按钮。我无法让切换按钮(顶部)正常工作,删除很好。这是现在的情况。
def which_button(reportapproval)
if reportapproval.user_approved == false
button_to "Approve this Manager?", { controller: "users/reportapprovals", id: @reportapproval.id, action: "#not sure what goes here" }, method: :#not sure what goes here, data: {confirm: "Are you sure you want to give this manager access to your report?" }
else
button_to "Remove this Manager", { controller: "users/reportapprovals", id: @reportapproval.id, action: "destroy" }, method: :delete, data: {confirm: "Are you sure you want to remove this manager's access to your report?" }
end
end
但我不断收到错误 Post route no found 我知道这是不正确的。我希望这可以在 reportapproval 模型中切换一个布尔值。请告诉我我需要做什么。
【问题讨论】:
-
您需要在控制器中将第一个按钮设置为将
reportapproval.user_approved设置为true 的操作。 -
所以我应该在控制器中创建一个独特的动作?我这样做了,但不确定如何调用该操作。我是否在此按钮的操作或方法区域中调用它,以及在此按钮的另一个中调用它。
-
在第二个动作中调用它。它调用动作销毁。
-
好的,我会在操作中调用它,但是方法中发生了什么,更新?
-
只需删除该方法或使用 get 或发布您在路线中定义的任何要求/任何内容。请记住为您创建的操作设置路线。
标签: ruby-on-rails boolean button-to