如何在Rubi on Rails的视图中使用模型的属性?
我的模特:
class EntryItems < ActiveRecord::Base
attr_accessible :created_on, :updated_on, :activity_type, :date_from, :date_to
attr_protected :user_id, :from_tyear, :from_tmonth, :from_tday
@@date_from = nil
def date_from
@@date_from = Date.new(read_attribute(:from_tyear), read_attribute(:from_tmonth), read_attribute(:from_tday))
end
def date_from=(date_from_value)
if date_from_value.is_a?(Time)
@@date_from = date_from_value.to_date
end
write_attribute(:from_tyear, date_from_value.year)
write_attribute(:from_tmonth, date_from_value.mon)
write_attribute(:from_tday, date_from_value.mday)
end
end
我的控制器:
class ItemEntriesSetupController < ApplicationController
unloadable
def index
@item_entry = DayoffEntries.new(:user => User.current, :created_on => Time.now, :updated_on => Time.now)
@item_entry_post_url = url_for(:controller => 'item_entries_setup', :action => 'update')
end
def update
#code is skipped
end
end
我的观点:
<%= form_tag(@item_entry_post_url) do %>
<dl>
<label>Issues:</label>
<%=date_field_tag 'date_from', true, @item_entry.date_from %>
</dl>
<%= submit_tag(l(:button_create)) %>
<% end %>
它以underfined method 'div' for nil:NilClass
失败。
我做错了什么?
(我在Ruby on Rails中真的很新,所以我仍然遇到找到正确实践的问题,因为有很多代码示例以不同的风格编写)。