我有像这样在本地更新我的Lead
对象精细制作一个按钮:Rails:Heroku不明白:patch /:put请求?
<%= 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上找不到页面错误。
这是怎么回事?
看起来它正在将它作为“get”请求处理,而不是更新。在更新操作中记录一些内容以确保你进入该操作。 – toddmetheny
你的id也在'lead'之外。所以如果你用'params [:id]'来查看它,你需要通过'params ['lead'] ['status']'来查看状态......这对我来说看起来有点儿滑稽。我会将所有内容都传递给“lead”或其他所有内容。 – toddmetheny
它只是触及获取请求,是的 - 我猜Heroku不支持链接中的HTTP动词?这感觉很奇怪。我可以做自定义路线,但我并不是很想。 –