2

Category と Post の 2 つのモデルがあります。

カテゴリー.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):

どうすれば修正できますか?ありがとうございました!

4

1 に答える 1

0

問題は修正されました。カルロス・アントニオ・ダ・シルバに感謝します:D.

http://groups.google.com/group/plataformatec-simpleform/browse_thread/thread/f384f0445af8468eまたは:

<%= f.input :category, :collection => Category.all, :prompt => "Choose a Category" %>

ありがとうございました!

于 2012-05-06T22:26:51.587 に答える