我在相关视图文件夹下的编辑文件中有一个表单。我想将此表单导向编辑路线。
这是我的表格,
<%= form_with(model: @trade, local: true) do |form| %>
<%= form.button "Accept", name: "button_action", value: "accept" %>
<%= form.button "Deny", name: "button_action", value: "decline" %>
<% end %>
我在相关控制器中的编辑操作
def edit
@trade = Trade.find(params[:id])
if params['button_action'] == 'accept'
@trade.update(status: 1)
else
@trade.update(status: 2)
end
redirect_to root_path
end
还有我的路线,
book_trades GET /book/:book_id/trades(.:format) trades#index
POST /book/:book_id/trades(.:format) trades#create
new_book_trade GET /book/:book_id/trades/new(.:format) trades#new
edit_book_trade GET /book/:book_id/trades/:id/edit(.:format) trades#edit
book_trade GET /book/:book_id/trades/:id(.:format) trades#show
PATCH /book/:book_id/trades/:id(.:format) trades#update
PUT /book/:book_id/trades/:id(.:format) trades#update
DELETE /book/:book_id/trades/:id(.:format) trades#destroy
但我不能直接得到没有路线匹配错误。我是ruby和编程的新手,我缺少什么?
提前谢谢。
edit方法用于呈现表单。表单操作将向update方法发送PUT请求。
您需要保持将edit
方法中的逻辑移动到update
方法