Rails:Heroku不明白:patch /:put requests?

时间:2016-11-15 17:32:43

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

我有一个像这样的按钮,可以在本地更新我的Lead对象:

<%= link_to status.to_s.titlecase, lead_path(@lead, lead: { status: status }), method: :patch, class: 'dropdown-item' %>

但远程(在Heroku上)没有任何反应。日志中没有任何用处:

2016-11-15T17:23:45.013893+00:00 heroku[router]: at=info method=GET path="/leads/2562?lead%5Bstatus%5D=contact_established" host=app.herokuapp.com request_id=57e8b4e9-7a61-4b86-85eb-8f68f1fedd43 fwd="IP" dyno=web.1 connect=1ms service=44ms status=200 bytes=9678
2016-11-15T17:23:44.972753+00:00 app[web.1]: [57e8b4e9-7a61-4b86-85eb-8f68f1fedd43] Started GET "/leads/2562?lead%5Bstatus%5D=contact_established" for IP at 2016-11-15 17:23:44 +0000
2016-11-15T17:23:44.974230+00:00 app[web.1]: [57e8b4e9-7a61-4b86-85eb-8f68f1fedd43] Processing by LeadsController#show as HTML
2016-11-15T17:23:44.974316+00:00 app[web.1]: [57e8b4e9-7a61-4b86-85eb-8f68f1fedd43]   Parameters: {"lead"=>{"status"=>"contact_established"}, "id"=>"2562"}
2016-11-15T17:23:44.988214+00:00 app[web.1]: [57e8b4e9-7a61-4b86-85eb-8f68f1fedd43]   [1m[36mUser Load (11.5ms)[0m  [1m[34mSELECT  "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2[0m  [["id", 1], ["LIMIT", 1]]
2016-11-15T17:23:44.990722+00:00 app[web.1]: [57e8b4e9-7a61-4b86-85eb-8f68f1fedd43]   [1m[36mLead Load (1.0ms)[0m  [1m[34mSELECT  "leads".* FROM "leads" WHERE "leads"."id" = $1 LIMIT $2[0m  [["id", 2562], ["LIMIT", 1]]
2016-11-15T17:23:44.992582+00:00 app[web.1]: [57e8b4e9-7a61-4b86-85eb-8f68f1fedd43]   Rendering leads/show.html.erb within layouts/application
2016-11-15T17:23:45.007497+00:00 app[web.1]: [57e8b4e9-7a61-4b86-85eb-8f68f1fedd43]   Rendered leads/show.html.erb within layouts/application (14.7ms)
2016-11-15T17:23:45.009303+00:00 app[web.1]: [57e8b4e9-7a61-4b86-85eb-8f68f1fedd43] Completed 200 OK in 35ms (Views: 17.2ms | ActiveRecord: 12.6ms)

flash没有回复任何错误消息。我在:patch:put之间更改了方法,但仍然没有。

我错过了什么?为什么link_to在本地更新记录而在Heroku上什么都不做?

更新

为了Heroku的缘故尝试了一条自定义路线:

resources :leads do
  member do
    patch 'update', to: 'leads#update', as: :update
  end
end

并更改了我的链接以使用新路径:

<%= link_to status.to_s.titlecase, update_lead_path(@lead, lead: { status: status }), method: :patch, class: 'dropdown-item' %>

在本地工作,我在Heroku上找不到页面错误。

这是什么交易?

1 个答案:

答案 0 :(得分:0)

因此,出于纯粹的烦恼,我提出了Heroku可以理解的:get请求。以下是这些路线:

resources :leads do
  member do
    get 'change', to: 'leads#change', as: :change
  end
end

Controller (注意非标准参数)

def change
  if @lead.update_attributes(change_lead_params)
    notice = "#{helpers.full_name(@lead)} changed."
    redirect_to lead_path(@lead), notice: notice
  else
    flash.now[:error] = "#{@lead.errors.full_messages.to_sentence}."
    render :show
  end
end

private

def change_lead_params
  params.permit(:status, :loan_product)
end

link_to

<%= link_to status.to_s.titlecase, change_lead_path(@lead, status: status), class: 'dropdown-item' %>

有关此问题的任何信息都会受到赞赏,因为Heroku没有理由拒绝:put个请求,对吗?