我是 ruby 新手,遇到了问题
= simple_form_for @user do |f|
.form-inputs
= f.input :name
= f.input :email
= f.input :group_id, collection: Group.all.collect {|c| [c.name, c.id]}
.form-actions
= f.button :submit
给我一条错误消息的行是这样的:
= f.input :group, collection: Group.all.collect {|c| [c.name, c.id]}
同样的事情
= f.input :group, collection: @groups
用户:
class User < ActiveRecord::Base
attr_accessible :email, :name, :group
belongs_to :group
群组:
class Group < ActiveRecord::Base
attr_accessible :description, :name
has_many :users
我还使用了gem“移民”,它创建了外键和这个迁移:
class AddKeys < ActiveRecord::Migration
def change
add_foreign_key "users", "groups", :name => "users_group_id_fk"
end
end
我在这里看到了关于集合和表单构建器的警告。当我使用
= f.input :group_id, collection: @groups
它甚至在加载页面之前提示我一条错误消息(而不是在提交表单之后)
undefined method `group_id'
有什么帮助吗?