我正在尝试使用event_calendar gem,我遵循这3个指南 http://andolasoft.wordpress.com/2013/01/09/how-to-implement-event-calendar-in-rails-app/ https://github.com/elevation/event_calendar#static-files https://github.com/elevation/event_calendar/wiki/Quickstart-from-scratch
我认为我的问题是关于样式表和javascript的包含。 我无法理解包括的步骤,因为每个导游都说不同的东西。
继承错误
Calendar#index中的TypeError 显示/home/user/work/aptana_1/spree_calendar/app/views/calendar/index.html.erb其中>第6行引发:
没有将nil隐式转换为Hash 提取的来源(第6行):
<h1>Calendar</h1>
<%= event_calendar %>
>Rails.root: /home/user/work/aptana_1/spree_calendar
>
>Application Trace | Framework Trace | Full Trace
>app/helpers/calendar_helper.rb:24:in `event_calendar'
>app/views/calendar/index.html.erb:6:in >`_app_views_calendar_index_html_erb___345437905_81942130'
>Request
>
>Parameters:
>
>{"year"=>"2014",
> "month"=>"07"}
这是calendar_helper文件
module CalendarHelper
def month_link(month_date)
link_to(I18n.localize(month_date, :format => "%B"), {:month => month_date.month, :year => month_date.year})
end
# custom options for this calendar
def event_calendar_opts
puts("EVENTCALENDAROP")
{
:year => @year,
:month => @month,
:event_strips => @event_strips,
:month_name_text => I18n.localize(@shown_month, :format => "%B %Y"),
:previous_month_text => "<< " + month_link(@shown_month.prev_month),
:next_month_text => month_link(@shown_month.next_month) + " >>"
}
puts"###{@year}"
puts"###{:year.to_s}"
end
def event_calendar
# args is an argument hash containing :event, :day, and :options
puts "EVENT_CALENDAR"
calendar event_calendar_opts do |args|
event = args[:event]
%(<a href="/events/#{event.id}" title="#{h(event.name)}">#{h(event.name)}</a>)
end
end
end
这是视图
<!-- Probably move the stylesheet to you layout. Also make sure you include the javascript. -->
<%= stylesheet_link_tag "event_calendar" %>
<h1>Calendar</h1>
<%= event_calendar %>
这是应用程序布局
<!DOCTYPE html>
<html>
<head>
<title>SpreeCalendar</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true ,'event_calendar'%>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
答案 0 :(得分:0)
问题出在这个方法中:
def event_calendar_opts
puts("EVENTCALENDAROP")
{
:year => @year,
:month => @month,
:event_strips => @event_strips,
:month_name_text => I18n.localize(@shown_month, :format => "%B %Y"),
:previous_month_text => "<< " + month_link(@shown_month.prev_month),
:next_month_text => month_link(@shown_month.next_month) + " >>"
}
puts "###{@year}"
puts "###{:year.to_s}"
end
我相信最后两次调用puts
是调试输出,但它们会更改#event_calendar_opts
的返回值。您应该删除puts
或将其移至顶部:
def event_calendar_opts
puts("EVENTCALENDAROP")
puts "###{@year}"
puts "###{:year.to_s}"
{
:year => @year,
:month => @month,
:event_strips => @event_strips,
:month_name_text => I18n.localize(@shown_month, :format => "%B %Y"),
:previous_month_text => "<< " + month_link(@shown_month.prev_month),
:next_month_text => month_link(@shown_month.next_month) + " >>"
}
end