2
カテゴリと投稿という2つのモデルがあります。未定義メソッド `valid_options 'for nil:simple_formとMongoidを持つNilClass
:私は私の記事で書いた場合、次を形成 simple_form gemを使用してい
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_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形式で次の形式を使用している場合:私はそれを修正するにはどうすればよい
Completed 500 Internal Server Error in 23ms
ActionView::Template::Error (undefined method `valid_options' for nil:NilClass):
:
<%= simple_form_for(@post) do |f| %>
<%= f.association :category, :prompt => "Choose a Category" %>
<%= f.input :title %>
<%= f.button :submit %>
<% end %>
を私は次のエラーを取得しますか? ありがとうございました!
これは実際には解決策ではなく、回避策が増えています。 –
私のために働かないでください(多分私のチェックボックスの必要性のために)。これは動作します: = f.association:categories、:collection => Category.all、::check_boxes –