我的Rails 3.1应用程序中有一个不受表支持的模型。事实上,我甚至没有从ActiveModel继承(这可能是一个错误......)。
我想使用生成器来创建一个视图,因为这个模型有67个attrs(用户希望偶尔指定某个attr中的内容,其他时候是默认值)。
当我运行rails g controller TestDataRecords index show edit new destroy create update
时,我没有预先填充视图。
有什么想法吗?
模型
class TestDataRecord
belongs_to :test_data_set
attr_accessor :sample_attr # repeat 66 times
def after_initilize
return unless new_record?
self.sample_attr = "default value"
end
end
答案 0 :(得分:1)
退房: https://github.com/ryanb/nifty-generators 对于一个伟大的gem,它将为您提供选择要为其生成视图的控制器操作的选项。