【问题标题】:How can I pass parameter to event calendar helper?如何将参数传递给事件日历助手?
【发布时间】:2011-09-19 04:53:35
【问题描述】:

我正在使用带有 rails 2.3.8 的 event_calendarplugin。我有带有名称、地点和培训师列的活动表。我想根据培训师和场地为活动着色。我可以让教练给它上色。但是现在我想将参数传递给事件日历助手,考虑它是培训师还是场地。我应该如何传递这个参数?有人使用这个插件吗?请帮帮我....

【问题讨论】:

    标签: ruby-on-rails ruby


    【解决方案1】:

    如果你看一下 README.rdoc,你会得到 ​​p>

      <%= event_calendar %>
    
    
    ==Default Options
    
    The default options for the calendar are:
    
      defaults = {
        :year => Time.zone.now.year,
        :month => Time.zone.now.month,
        :abbrev => true,
        :first_day_of_week => 0, # See note below when setting this
        :show_today => true,
        :month_name_text => Time.zone.now.strftime("%B %Y"),
        :previous_month_text => nil,
        :next_month_text => nil,
        :event_strips => [],
    
        # it would be nice to have these in the CSS file
        # but they are needed to perform height calculations
        :width => nil,
        :height => 500, 
        :day_names_height => 18,
        :day_nums_height => 18,
        :event_height => 18,
        :event_margin => 1,
        :event_padding_top => 1,
    
        :use_all_day => false,
        :use_javascript => true,
        :link_to_day_action => false
      }
    

    我在日历中采用以下两个参数,并在

    中覆盖插件辅助方法
    <%= event_calendar(user.format, outbound) %>
    

    app/helpers/calendar_helper.rb

      def event_calendar_opts(display_format, outbound)
        {
          :year => @year,
          :month => @month,
          :abbrev => nil,
          :event_strips => @event_strips,
          :display_properties => (display_format==4)? 4 : 3,
          :outbound => outbound,
          :month_name_text => I18n.localize(@shown_month, :format => "%B %Y"),
          :previous_month_text => month_link(@shown_month.last_month),
          :next_month_text => next_month_link(@shown_month.next_month)    }
      end
    
      def event_calendar(display_format, outbound)
        # args is an argument hash containing :event, :day, and :options
        index = 0
        calendar event_calendar_opts(display_format, outbound) do |args|
          html << some_html
          html
        end
      end
    

    【讨论】:

    • 我可以像上面那样将参数传递给 vendor\plugins\event_calendar\lib\event_calendar\calendar 助手吗?我试图通过它。但是有错误。
    • @Rosh:- 是的,您可以使用上述方法将参数传递给插件的辅助方法。在我的示例中,您可以在插件的帮助程序中获取参数,例如 options[:display_properties]。重要的是,无论何时您更改插件,都请重新启动我们的服务器。
    猜你喜欢
    • 1970-01-01
    • 2013-08-14
    • 2021-11-20
    • 1970-01-01
    • 2015-09-02
    • 1970-01-01
    • 1970-01-01
    • 2013-09-25
    • 1970-01-01
    相关资源
    最近更新 更多