首页 > 解决方案 > 不确定要添加到我的路线以获取 icalendar gem 链接

问题描述

我的索引页面显示

<%= link_to 'Subscribe', icalendar_url(protocol: :webcal, format: :ics) %>

在我的控制器上,我添加了

   respond_to do |format|
  format.html
  format.ics do
    cal = Icalendar::Calendar.new
    cal.x_wr_calname = 'Awesome Rails Calendar'
    cal.event do |e|
      e.scheduled_date     = @clients.scheduled_date
      e.summary     = '@clients.work_needed'
      e.description = '@clients.comments'
    end
    cal.publish
    render plain: cal.to_ical
  end

结尾

并没有在我的 client.rb 中添加任何内容

我该怎么办我得到错误

undefined method `icalendar_url' for #<#<Class:0x007fbb1a4b92b8>:0x007fbb32fc8560>

标签: ruby-on-railsicalendar

解决方案


我的错误是我试图解决路由中的问题,链接中的路由错误与路由无关

我有一个链接设置为

<%= link_to "CSV", calendar_path(format: "csv"), :class => 'glyphicon glyphicon-file' %>

中间的 calendar_path 不是我的控制器,我的控制器是 clients_path

一个简单的改变

<%= link_to "CSV", clients_path(format: "csv"), :class => 'glyphicon glyphicon-file' %>

有用 !


推荐阅读