我有两个型号,类别和邮政业。
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宝石
如果我在我的文章写的形成下:
<%= 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):
我怎样才能解决这个问题? 谢谢!