一个Struck常数不允许我创建一个日历

时间:2016-04-27 09:40:05

标签: ruby-on-rails

我正在尝试制作日历,并且一直关注YouTube calendar ruby on rails第一个视频的教程。一旦我输入了代码,我就出错了,

  

未初始化的常量CalenderHelper :: Struck

代码是;

module CalenderHelper
def calender(date = Date.today, &block)
    Calender.new(self, date, block).table
end

**class Calender < Struck.new(:view, :date, :callback)**
    HEADER = %w[Sunday Monday Tuesday Wednesday Thursday Friday Saturday]
    START_DAY = :sunday 

    delegate :content_tag, to: :view

def table
    content_tag :table, class: "calender" 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
    week.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
end 

错误的行是标记,每边都有启动

1 个答案:

答案 0 :(得分:1)

你有一个小的拼写错误:

你想要调用Struct类,而不是Struck。

你的行应该是:

class Calendar < Struct.new(:view, :date, :callback)
    # the rest of the code
end

希望有所帮助