Rails3:form_for / simple_form_for记录值

时间:2012-02-08 14:36:00

标签: ruby-on-rails forms activerecord

如何从表单对象(@ banner.name)中读取记录参数?

= simple_form_for @banner |f|
  = f.name
  ...
  = f.simple_fields_for :params do |o|
    = o.name ????
    = o.created_at ????

1 个答案:

答案 0 :(得分:2)

试试这种方式

= simple_form_for @banner |f|
  = f.input :name
  ...
  = f.simple_fields_for :params do |o|
    = o.input :name
    = o.input :created_at, :as => :date

但我不确定为什么你需要输入created_at。无论如何,带有示例的文档位于their Github page

只显示值object方法

= simple_form_for @banner |f|
  = f.object.name
  ...
  = f.simple_fields_for :params do |o|
    = o.object.name
    = o.object.created_at.strftime('%x %X') # strftime just to format