I have two models, Category and 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
I'm using simple_form gem
If I write in my post form the next:
<%= 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 %>
The form does works fine :).
but if I use the next form with simple_form format:
<%= simple_form_for(@post) do |f| %>
<%= f.association :category, :prompt => "Choose a Category" %>
<%= f.input :title %>
<%= f.button :submit %>
<% end %>
I get the next error:
Completed 500 Internal Server Error in 23ms
ActionView::Template::Error (undefined method `valid_options' for nil:NilClass):
How can I fix it? Thank you!