Rails 3.2
在我的routes.rb文件,我有:自定義路線
namespace :admin do
resources :tickets, except: [:edit] do
member do
put 'save_and_close', to: 'tickets#save_and_close'
end
end
end
在我的控制器/管理/ tickets_controller.rb,我有:
def save_and_close
success_message = I18n.t('notices.ticket_successfully_updated')
@ticket = Ticket.find params[:id]
@ticket.assign_attributes(params[:ticket])
if @ticket.save
redirect_to admin_tickets_path, notice: success_message
else
flash.now[:error] = @ticket.errors.full_messages.join(', ')
render action: "show"
end
end
在我的看法/admin/tickets/show.html.slim,我有:
= link_to 'Save & Close', save_and_close_admin_ticket_path, class: 'btn btn-success ticket-event btn-lg'
從ra柯路線,我有:
save_and_close_admin_ticket PUT /admin/tickets/:id/save_and_close(.:format) admin/tickets#save_and_close
但是,當我點擊保存&關閉按鈕,我收到以下錯誤信息:
Started GET "/admin/tickets/163925/save_and_close" for 73.83.66.151 at 2017-03-02 05:26:22 +0000
Processing by ApplicationController#routing_error as HTML
Parameters: {"unmatched_route"=>"admin/tickets/163925/save_and_close"}
Completed 404 Not Found in 28.2ms
ActionController::RoutingError (No route matches admin/tickets/163925/save_and_close):
任何想法?
它應該是@票務,而不是票(傳遞給路徑),但是,我忘了指定一個方法,否則它的工作原理 – EastsideDeveloper
複製上一個人的答案。 – Nickey
@Nickey你以前答案的副本是什麼意思? – ashvin