【发布时间】:2012-05-04 16:23:20
【问题描述】:
我有两个模型,Category 和 Post。
Category.rb
class Category
include Mongoid::Document
field :title, :type => String
has_many :posts, :autosave => true, dependent: :destroy
end
Post.rb
class Post
include Mongoid::Document
field :title, :type => String
belongs_to :category
end
我正在使用 simple_form gem
如果我在我的帖子中写下一个:
<%= simple_form_for(@post) do |f| %>
<%= f.collection_select :category, Category.all, :id, :title, :prompt => "Choose a Category"%>
<%= f.input :title %>
<%= f.button :submit %>
<% end %>
表单确实可以正常工作:)。
但如果我使用 simple_form 格式的下一个表单:
<%= simple_form_for(@post) do |f| %>
<%= f.association :category, :prompt => "Choose a Category" %>
<%= f.input :title %>
<%= f.button :submit %>
<% end %>
我得到下一个错误:
Completed 500 Internal Server Error in 23ms
ActionView::Template::Error (undefined method `valid_options' for nil:NilClass):
我该如何解决? 谢谢!
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 mongoid simple-form