Rails方法:: put route starts'Get'

问题描述 投票:0回答:1

我在我的routes.rb中有这个:

scope '/financial' do
  get '',                to: 'financial#index',    as: :financial
  get ':debnr',          to: 'financial#debnr',    as: :financial_debnr
  get ':debnr/pdf/:id',  to: 'financial#pdf',      as: :financial_pdf
  put ':debnr/pdf/:id',  to: 'financial#update',   as: :update_pdf
end

然后我在我的pdf.html.haml中有这个:

= link_to 'Complete this pdf', 
           update_pdf_path(@debnr, @pdf), 
           method: :put, 
           data: { confirm: "You sure?"}

在我的FinancialController

def update
  @pdf = Pdf.find(params[:id])
  @pdf.update_attribute(completed: true)
  redirect_to root_path
end

不幸的是,当我点击按钮,完成pdf时,它无法正常工作。它启动了正常的get动作,如下所示:

Started GET "/financieel/20308/pdf/67" for 127.0.0.1 at 2019-03-15 10:44:53 +0100
Processing by FinancieelController#pdf as HTML

它甚至没有说出“你确定吗?”的信息。并完全忽略了method: :put。有什么想法吗?

Edit

HTML看起来像这样:

<a data-confirm="You sure?" rel="nofollow" data-method="put" href="/financial/123456/pdf/42">Complete this pdf</a>

Second Edit

我找到了。我一直在搞头,我不小心把所有的javascript文件都注释掉了。

对不起大家!

ruby-on-rails routes
1个回答
0
投票

也许你没有将rails-ujs(或jquery-ujs)添加到项目中?

© www.soinside.com 2019 - 2024. All rights reserved.