我有我的看法#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