0
我已經成功解決該問題無不能強迫Fixnum對象,但我得到另一個:(錯誤,當我嘗試去calendars_path(零不能強迫Fixnum對象)
沒有給出塊(產率)
我知道問題是上的index.html線8,但我不知道來解決它
模塊CalendarHelper
def calendar(date = Date.today, &block)
Calendar.new(self, date, block).table
end
class Calendar < Struct.new(:view, :date, :callback)
HEADER = %w[Monday Mardi Mercredi jeudi Vendredi Samedi Dimanche]
START_DAY = :monday
delegate :content_tag, to: :view
def table
content_tag :table, class: "calendar" do
header + week_rows
end
end
def header
content_tag :tr do
HEADER.map { |day| content_tag :th, day }.join.html_safe
end
end
def week_rows
weeks.map do |week|
content_tag :tr do
week.map { |day| day_cell(day) }.join.html_safe
end
end.join.html_safe
end
def day_cell(day)
content_tag :td, view.capture(day, &callback), class: day_classes(day)
end
def day_classes(day)
classes = []
classes << "today" if day == Date.today
classes << "notmonth" if day.month != date.month
classes.empty? ? nil : classes.join(" ")
end
def weeks
first = date.beginning_of_month.beginning_of_week(START_DAY)
last = date.end_of_month.end_of_week(START_DAY)
(first..last).to_a.in_groups_of(7)
end
end
端
CONTROLER calendars_controller.rb
def index
@content_calendars = Calendar.all
@content_calendars_by_dates = @content_calendars.group_by(&:published_on)
@date = params[:date] ? Date.parse(params[:date]) : Date.today
end
def show
@calendar = Calendar.find(params[:id])
end
的index.html
1 <%= calendar @date do |date| %>
2 <%= date.day %>
3
4 <!--# <%= debug(params) if Rails.env.development? %>
5 --><% if @content_calendars_by_dates[date] %>
6 <ul>
7
8 <% @content_calendars_by_dates[date].each do |article| %>
9 <li><%= link_to calendar.event, article %></li>
10 <% end %>
11
12 </ul>
13 <% end %>
14 <% end %>
Ryans日曆應用程序我已經成功地解決問題零不能強制進入Fixnum – zyriuse 2013-05-09 16:18:21
我遵循railscast的教程 – zyriuse 2013-05-09 16:26:34
我已經通過等待解決了我的問題。當我回來3個小時後,每個人都可以! – zyriuse 2013-05-12 18:59:15