Ruby on rails 尝试获取每周第一天时未定义的方法-Rails 5

Ruby on rails 尝试获取每周第一天时未定义的方法-Rails 5,ruby-on-rails,ruby-on-rails-5,Ruby On Rails,Ruby On Rails 5,我在做日历,我试图得到一周的第一天,以及一周的最后一天。尝试执行此操作时,我在/lib/calencar.rb中遇到一个错误: undefined method `beginning_of_month 'for {: date => Wed, 23 Jan 2019}: Hash 这是代码calendar.rb class Calendar < Struct.new(:view, :date, :callback) HEADER = %w[Sunday Monday Tue

我在做日历,我试图得到一周的第一天,以及一周的最后一天。尝试执行此操作时,我在
/lib/calencar.rb
中遇到一个错误:

undefined method `beginning_of_month 'for {: date => Wed, 23 Jan 2019}: Hash
这是代码calendar.rb

class Calendar < Struct.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: "calendar table table-bordered table-striped" 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 << "not-month" if day.month != date.month
      classes.empty? ? nil : classes.join(" ")
    end

    def weeks
      #first = DateTime.strptime(date, "%B %d, %Y")
      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
多谢各位

undefined method `beginning_of_month 'for {: date => Wed, 23 Jan 2019}: Hash

如果您试图在
哈希
而不是
日期时间
对象上使用
月初
方法,请检查
日期
变量的赋值。

现在我遇到另一个错误:
内容标签中没有给出块(收益)
:td,view.capture(day,&callback),class:day\u类(day)
捕获
中删除
回调
,它看起来是这样的:`content\u标记:td,view.capture(day),class:day\u classes(day)`,但它仍然显示相同的错误,您需要将
传递给
捕获
,让我们来看看。
undefined method `beginning_of_month 'for {: date => Wed, 23 Jan 2019}: Hash