我在这里使用 CalendarHelper http://railscasts.com/episodes/213-calendars-revised
它显示当前月份,如下所示:
class XyController < ApplicationController
@date ||= Date.today
我想在视图中有一个表格,所以我可以将此日期设置为任何自定义日期。像这样的东西:
= simple_form_for(@date) do |f|
= f.input ???
我想我可能错过了如何为实例对象设置表单的要点。我如何实现一个表单来为我在控制器中设置的实例变量设置日期?
编辑。:
calendar_helper.rb
module CalendarHelper
def calendar(date = Date.today, &block)
Calendar.new(self, date, block).table
end
class Calendar < Struct.new(:view, :date, :callback)
HEADER = %w[Hétfő Kedd Szerda Csütörtök Péntek Szombat Vasárnap]
START_DAY = :monday
delegate :content_tag, to: :view
def table
content_tag :table, class: "calendar" do
header + week_rows
end
end
def header
...
end
def week_rows
...
end
def day_cell(day)
...
end
def day_classes(day)
...
end
def weeks
...
end
end
end
在视图中:
= calendar do |date|
= date.day
所以在助手中有 date = Date.today,我想将其更改为 @date 实例,并希望在一个简单的显示视图中设置它,例如:
profile_controller.rb
def show
@date ||= Date.today
end
在这样的视图中:
form_for(@date) 做 |f| f.date_select :日期
像这样的东西,但这显然不起作用也不正确