我想提出一個路線幫手在我的幫助形式行進至update
行動:什麼是Rails更新操作的路由幫助器?
<%= s3_uploader_form post: <route helper goes here>, as: "shop[logo_ori]" do %>
<%= file_field_tag :file %>
<% end %>
但是當我運行rake routes
我沒有看到PUT
一個幫手:
shops GET /shops(.:format) shops#index
POST /shops(.:format) shops#create
new_shop GET /shops/new(.:format) shops#new
edit_shop GET /shops/:id/edit(.:format) shops#edit
shop GET /shops/:id(.:format) shops#show
PUT /shops/:id(.:format) shops#update
的問題形式的幫手來自Railscasts#383的source。我發現上傳表單對於創建一個新的模型對象非常有用,但我正在努力使它更新模型對象。
當我試圖路線幫手shops_url
,它運行失敗POST
動作:
Started POST "/shops" for 127.0.0.1 at 2012-12-27 01:10:22 +0800
Processing by ShopsController#create as */*
Parameters: {"shop"=>{"logo_ori"=>"https://bucket.s3.amazonaws.com/example.gif"}}
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
(0.1ms) BEGIN
(0.1ms) ROLLBACK
<additional output redacted>
任何幫助嗎?
'shops_url'看起來不錯,'ShopsController#create'被調用。什麼是錯誤? – Baldrick
@Baldrick我希望它指向更新操作,而不是創建。 –
當創建** POST /資源**時,更新路由*絕對不是*與創建路徑*相同,更新爲** POST/resources/id ** 您想要的是'shop_path(shop)'或'shop_path(shop_id)' – systho