应用找不到路线

时间:2018-09-06 20:31:47

标签: ruby-on-rails

Rails 3.2

在我看来,我有以下几点(苗条):

= link_to 'Delete', cancel_admin_ticket_path, data: { confirm: t('.confirm', default: t("helpers.links.confirm", default: 'Are you sure?')) }, class: 'btn btn-danger destroy-btn'

在我的admin / tickets_controller.rb中,我有:

def cancel
  @ticket = Ticket.find params[:id]
  existing_workflow_state = @ticket.workflow_state
  msg_success = "Ticket #{@ticket.number} status has been changed from  #{existing_workflow_state} to cancelled"
  msg_already_cancelled = "Ticket #{@ticket.number} is already cancelled"
  msg_failure = "Ticket #{@ticket.number} status is  #{@ticket.workflow_state}, it cannot be cancelled"
  if existing_workflow_state == 'cancelled'
    redirect_to admin_tickets_path, alert: "Ticket #{@ticket.number} has already been cancelled"
  elsif !ticket_can_be_deleted(@ticket).nil?
    @ticket.workflow_state = 'cancelled'
    @ticket.save
    redirect_to admin_tickets_path, notice: "Ticket #{@ticket.number} status has been changed from  #{existing_workflow_state} to cancelled"
  else
    redirect_to admin_tickets_path, alert: "Ticket #{@ticket.number} status is  #{existing_workflow_state}, it cannot be cancelled"
  end
end

在我的route.rb中,我有:

namespace :admin do
  resources :tickets, except: [:edit] do
    member do
      put 'cancel', to: 'tickets#cancel'
    end
  end
end

当我耙路线时,这是我得到的路线:

cancel_admin_ticket PUT  /admin/tickets/:id/cancel(.:format) admin/tickets#cancel

当我尝试运行该应用程序时,出现以下错误消息:

Routing Error
No route matches {:action=>"cancel", :controller=>"admin/tickets"}

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

method: :put添加到link_to方法中,并将@ticket作为命名路由的参数:cancel_admin_ticket_path(@ticket)