Rails 3.2
В моем admin / tickets_controllers.rb у меня есть следующее:
def index
params[:direction] ||= "desc"
params[:sort] ||= "requested_date_start"
@tickets = Ticket.solr_search( include: [:customer_info, :customer, :executor, :notes] ){
fulltext params[:query] if params[:query].present?
with :status, (params[:status] || params[:filter]) if (params[:status] || params[:filter]).present?
order_by( params[:sort], params[:direction] ) if params[:sort].present? && params[:direction].present?
paginate :page => params[:page], per_page: params[:per_page]
}.results
render partial: 'tickets' if request.xhr?
end
def destroy
@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
private
def ticket_can_be_deleted(ticket)
w = ticket.workflow_state
if (w == 'closed') || (w == 'completed') || (w == 'submit_for_billing') || (w == 'needs_correction') || (w == 'cancelled')
return nil
else
return true
end
end
Следующий маршрут:
admin_tickets GET /admin/tickets(.:format) admin/tickets#index
Однако, когда я выполняю действие Уничтожить, ничего не происходит. Файл журнала говорит мне:
Started DELETE "/admin/tickets/177685" for xx.xxx.xxx.x at 2018-09-06 16:58:53 +0000
Processing by Admin::TicketsController#destroy as */*
Parameters: {"id"=>"177685"}
......
Redirected to http://test.myapp.com/admin/tickets
Completed 302 Found in 43.8ms (ActiveRecord: 30.9ms)
Started DELETE "/admin/tickets" for xx.xxx.xxxx.xx at 2018-09-06 16:58:54 +0000
Processing by ApplicationController#routing_error as */*
Parameters: {"unmatched_route"=>"admin/tickets"}
....
Completed 404 Not Found in 14.0ms
ActionController::RoutingError (No route matches admin/tickets):
app/controllers/application_controller.rb:129:in `routing_error'
app/middleware/catch_json_parse_errors.rb:8:in `call'
Но, если я нажму кнопку обновления браузера, сразу же после этого я получу Индекс заявок, в верхней части которого появится следующее предупреждение:
Ticket 177685 has already been cancelled
И файл журнала содержит:
Started GET "/admin/tickets" for xx.xxx.xxx.x at 2018-09-06 17:05:07 +0000
Processing by Admin::TicketsController#index as HTML
.....
Rendered shared/_index_search_form.html.slim (0.8ms)
Rendered admin/tickets/_ticket.html.slim (87.5ms)
Rendered shared/_no_result.html.slim (0.0ms)
Rendered admin/tickets/index.html.slim within layouts/application (95.8ms)
Completed 200 OK in 140.2ms (Views: 101.5ms | ActiveRecord: 14.7ms | Solr: 4.0ms)
Есть идеи, почему представление индекса admin / tickets не отображается, и для этого нужно обновить браузер?