button_to无法打开确认对话框

时间:2019-07-14 17:39:32

标签: ruby-on-rails ruby-on-rails-5

我具有以下链接来更新我的应用程序上的应用程序状态。该模型称为hardships(即hardship ==单个应用程序),而我的hardships_controller.rb中的方法如下:

 def withdraw_application
    @hardship = Hardship.find(params[:id])
    @hardship.update_attributes(status: "Withdrawn")
    if @hardship.update_attributes(status: "Withdrawn")
        redirect_back(fallback_location: user_path(current_user))
        flash[:notice] = "That application has been withdrawn!"
    else
        redirect_to user_path(current_user)
        flash[:warning] = "Something went wrong.  Please try your request again later."
    end
  end

我的路线中有这条线:

post "hardships/:id/withdraw_application" => "hardships#withdraw_application", as: "withdraw_application"

我用一个button_to链接来称呼它。 (我更喜欢link_to,但是显然那些不再通过post起作用吗?):

<% @hardships.each do |hardship| %>
   ...
   <%= button_to "Withdraw", withdraw_application_path(hardship), method: :post, data: { confirm: "Are you sure you want to withdraw your application?"} %>
<% end %>

所需的行为是,它弹出一个确认按钮,然后将hardship的状态更新为“已撤回”。但是,它不会弹出确认对话框,而只是立即处理该方法。

谁能看到为什么不进行此对话?理想情况下,我希望它驻留在控制器中而不是链接中,但是任何正常运行的对话框都很好。谢谢!

0 个答案:

没有答案