ruby on rails - Controller method #show getting called -
i have link on #index
view:
<%= link_to 'export calendar (ics)', { controller: :tickets, action: :ics_export, format: :ics }, class: "class-needed right" %>
routes.rb
pertains this:
resources :tickets 'tickets/calendar' => 'tickets#ics_export' post 'tickets' => 'tickets#index' patch 'tickets/:id/close' => 'tickets#close', as: 'close_ticket' post 'tickets/:id' => 'ticket_comments#create'
my ticketscontroller
pertains:
before_action :set_ticket, only: [:show, :edit, :destroy, :update, :close] def show @ticket_comment = ticketcomment.new end def ics_export tickets = ticket.all respond_to |format| format.html format.ics cal = icalendar::calendar.new tickets.each |ticket| event = icalendar::event.new event.dtstart = ticket.start event.description = ticket.summary cal.add_event(event) end cal.publish render :text => cal.to_ical end end end private def set_ticket @ticket = ticket.find(params[:id]) end
and when click link, takes me /tickets/calendar.ics
correct following error:
activerecord::recordnotfound in ticketscontroller#show
couldn't find ticket 'id'=calendar
extracted source (around line #83):
private def set_ticket @ticket = ticket.find(params[:id]) end
the @ticket = ticket.find(params[:id])
highlighted. make sense failing call ticket id of calendar
.
request has parameters:
{"id"=>"calendar", "format"=>"ics"}
how fix error? why calling show action?
there footnote in canonical rails routing outside in effect:
rails routes matched in order specified, if have resources :photos above 'photos/poll' show action's route resources line matched before line. fix this, move line above resources line matched first.
as commented, fix specify get 'tickets/calendar' => ...
ahead of resources :tickets
. if order of routes in question, can run rake routes
, which, best of knowledge, should render routes in order checked.
Comments
Post a Comment