Ruby 如何添加事件源

Ruby 如何添加事件源,ruby,ruby-on-rails-3,calendar,fullcalendar,Ruby,Ruby On Rails 3,Calendar,Fullcalendar,在我的fullcalendar页面中,我有一个(默认)事件源区域,如下所示: eventSources: [{ url: '/events/index/', color: 'yellow', textColor: 'black', ignoreTimezone: false }], 我有一个名为“rentalcars”的模型(和视图)文件夹。如何使事件自动从该模型中提取?此模型有开始日期和结束日期 我试过: eventSources: [{ url: '

在我的fullcalendar页面中,我有一个(默认)事件源区域,如下所示:

eventSources: [{
    url: '/events/index/',
    color: 'yellow',
    textColor: 'black',
    ignoreTimezone: false
}],
我有一个名为
“rentalcars”
的模型(和视图)文件夹。如何使事件自动从该模型中提取?此模型有开始日期和结束日期

我试过:

eventSources: [{
    url: '/rentalcars/index/',
    color: 'yellow',
    textColor: 'black',
    ignoreTimezone: false
}],
这肯定行不通。我查看了arshaw的源代码,我知道如何生成静态事件,但我正在寻找动态事件:那些将在现有模型中迭代的事件


有什么建议吗?

您的url参数需要返回FullCalendar能够理解和解析的任何内容,因此根据判断,您必须确保您的
rentelcars
索引操作返回此特定格式:

{
        title  : 'event1',
        start  : '2010-01-01'
    },
    {
        title  : 'event2',
        start  : '2010-01-05',
        end    : '2010-01-07'
    },
    {
        title  : 'event3',
        start  : '2010-01-09 12:30:00',
        allDay : false // will make the time show
    }
}
因此,在
rentalcars\u controller.rb
中的
index
定义中,您必须确保返回的格式非常类似于JSON。因此,最简单的方法是将其作为JavaScript:

eventSources: [{
  url: '/rentalcars.json',
  color: 'yellow',
  textColor: 'black',
  ignoreTimezone: false
}],
然后在控制器中,您将有如下内容:

def index
    rentalcar_dates = RentelcarDates.all # assuming this is an object that holds start, end date and maybe the car name

    respond_to do |format|
        format.html
        format.json { render :json => rentalcar_dates }
    end
end

目前,rentalcars有很多属性,开始日期和结束日期只是其中的两个。我是否必须创建另一个名为RentalCarDates的表,其列名与“title,start,end…”完全匹配?或者我可以以某种方式获取这两列吗?是的,您可以简单地获取任意列,如so
Rentelcar.all.map{{r}{:title=>r.title,:start=>r.start,:end=>r.end}