Ruby on rails 4 完整日历和自动筛选事件Rails 4

Ruby on rails 4 完整日历和自动筛选事件Rails 4,ruby-on-rails-4,fullcalendar,filtering,Ruby On Rails 4,Fullcalendar,Filtering,我正在构建一个日历应用程序,它需要根据正在查看的位置在日历上显示某些事件。我有完整的日历,它显示数据库中的所有事件。我试图实现一个自动过滤器,只显示与正在查看的位置相关的事件 当前设置我的事件模型称为活动,以与我的应用程序保持一致 活动控制员 战役模式 我已经花了好几个小时试图弄明白这一点,但却没能在日历上得到同样的结果。有人能帮我弄清楚过滤与观看位置相关的活动需要什么吗 谢谢 你试过这个吗 eventSources: [{ url: '/campaigns', data: {

我正在构建一个日历应用程序,它需要根据正在查看的位置在日历上显示某些事件。我有完整的日历,它显示数据库中的所有事件。我试图实现一个自动过滤器,只显示与正在查看的位置相关的事件

当前设置我的事件模型称为活动,以与我的应用程序保持一致

活动控制员

战役模式

我已经花了好几个小时试图弄明白这一点,但却没能在日历上得到同样的结果。有人能帮我弄清楚过滤与观看位置相关的活动需要什么吗

谢谢

你试过这个吗

 eventSources: [{
    url: '/campaigns',
    data: { 'location': <%= @locations %> }, <- try this like so
    color: 'blue',
    textColor: 'white',
    ignoreTimezone: false
}],

我想知道是否应该尝试通过位置控制器运行活动检索,因为位置与活动:has_many:活动有关系
belongs_to :location 

scope :before, lambda {|end_time| {:conditions => ["ends_at < ?",  Campaign.format_date(end_time)] }}
scope :after, lambda {|start_time| {:conditions => ["starts_at > ?", Campaign.format_date(start_time)] }}

# need to override the json view to return what full_calendar is expecting.
# http://arshaw.com/fullcalendar/docs/event_data/Event_Object/

def as_json(options = {})
{
  :id => self.id,
  :title => self.name,
  :description => "",
  :start => starts_at.rfc822,
  :end => ends_at.rfc822,
  :allDay => false,
  :recurring => false,
  :url => Rails.application.routes.url_helpers.campaign_path(friendly_id)
  }

end

 def self.format_date(date_time)
   Time.at(date_time.to_i).to_formatted_s(:db)
 end
  $(document).ready(function() {

    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();

    $('#calendar').fullCalendar({
            editable: true,
            header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,agendaWeek,agendaDay'
    },
    defaultView: 'month',

    loading: function(bool){
        if (bool)
            $('#loading').show();
        else
            $('#loading').hide();
    },

    // a future calendar might have many sources.
    eventSources: [{
        url: '/campaigns',
        data: { <%= @locations %> }, #added but not filtering as I had hoped
        color: 'blue',
        textColor: 'white',
        ignoreTimezone: false
    }],

    timeFormat: 'h:mm t{ - h:mm t} ',
    dragOpacity: "0.5",


    });
   });
 <strong>Campaigns:</strong>
   <%= render partial: @campaigns %>
 </p>
  def show
   @campaigns = @location.campaigns
  end
 eventSources: [{
    url: '/campaigns',
    data: { 'location': <%= @locations %> }, <- try this like so
    color: 'blue',
    textColor: 'white',
    ignoreTimezone: false
}],