我有我的看法#index
鏈接:控制方法#show獲取調用
<%= link_to 'Export Calendar (ICS)', { controller: :tickets, action: :ics_export, format: :ics }, class: "class-needed right" %>
routes.rb
,涉及到這一點:
resources :tickets
get 'tickets/calendar' => 'tickets#ics_export'
post 'tickets' => 'tickets#index'
patch 'tickets/:id/close' => 'tickets#close', as: 'close_ticket'
post 'tickets/:id' => 'ticket_comments#create'
我TicketsController
是涉及:
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 do |format|
format.html
format.ics do
cal = Icalendar::Calendar.new
tickets.each do |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
當我點擊鏈接時,它會帶我到/tickets/calendar.ics
這是正確的,但我得到以下錯誤:
ActiveRecord::RecordNotFound in TicketsController#show
Couldn't find Ticket with 'id'=calendar
Extracted source (around line #83):
private
def set_ticket
@ticket = Ticket.find(params[:id])
end
的@ticket = Ticket.find(params[:id])
高亮顯示。這是有道理的,它是不能打電話給一個ID爲calendar
的票。
請求的參數爲:
{"id"=>"calendar", "format"=>"ics"}
如何解決這個問題?爲什麼它要求演出?
如果你把'get'tickets/calendar'=> ...''上面的'資源:tickets'?你的'耙路線'也許是有用的信息,否則。 – Kimball
是的。工作!你有沒有關於未來可能有幫助的路線順序的文件? –
我會用一個或兩個鏈接發佈更詳細的答案 – Kimball