simple_form的问题:has_many和belongs_to没有创建ID列?

时间:2013-04-21 05:29:59

标签: ajax ruby-on-rails-3 simple-form

我有三个模型,NeoUser(由Devise自动生成)和Observation

每个User has_many NeoObservation s。 每Neo has_many次观察和belongs_to User。 每个Observation belongs_to一个Neo和一个User

我需要为Neo创建一个simple_form,这应该允许我动态添加Observations(一个Polldaddy轮询选项)。这是我的表单代码:

- title "Add a NEO"

= simple_form_for @neo do |nf|
    = nf.input :name
        = nf.simple_fields_for :observations do |of|
            = of.input :ra
            = of.input :dec

    = nf.button :wrapped

这会返回ActiveRecord::UnkownAttributeError说“未知属性neo_id”。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

我的缩进错了:

- title "Add a NEO"

= simple_form_for @neo do |nf|
    = nf.input :name
        = nf.simple_fields_for :observations do |of|
            = of.input :ra
            = of.input :dec

    = nf.button :wrapped

应该是:

- title "Add a NEO"

= simple_form_for @neo do |nf|
    = nf.input :name
    = nf.simple_fields_for :observations do |of|
        = of.input :ra
        = of.input :dec

    = nf.button :wrapped