2012-03-18 5 views
0

基本的にレッスンとカテゴリを参照する以下のモデルがあります。各レッスンには1つのカテゴリがあり、各カテゴリはレッスンに埋め込まれています。Rails + MongoID + Simple Form関連:定義されていないメソッド `options 'for#<Mongoid :: Relations :: Metadata

class Lesson 
    include Mongoid::Document 

    field :title, :type => String 
    field :category, :type => String 
    field :price, :type => Integer 
    field :description, :type => String 
    field :user_id, :type => String 


    validates_presence_of :title 
    validates_presence_of :category 
    validates_presence_of :price 
    validates_presence_of :user_id 

    validates_numericality_of :price 

    attr_accessible :title, :category, :description, :price 

    embeds_one :category 
end 


class Category 
    include Mongoid::Document 
    field :name, type: String 

    embedded_in :lesson 
end 

そして、私はこのようなフォームしている:そのフォームをレンダリングしようとすると、私はこのエラーを取得する

<%= simple_form_for @lesson, :html => { :class => 'well' } do |lesson_form| %> 
<% if lesson_form.error_notification %> 
    <div class="alert alert-error fade in"> 
     <a class="close" data-dismiss="alert" href="#">&times;</a> 
     <%= lesson_form.error_notification %> 
    </div> 
<% end %> 
    <%= lesson_form.input :title %> 
    <%= lesson_form.input :category %> 
    <%= lesson_form.input :description %> 
    <%= lesson_form.input :price %> 
    <%= lesson_form.association :category %> 
    <%= lesson_form.button :submit, :label => 'Create', :class => 'btn btn-primary btn-large' %> 
<% end -%> 

を:

undefined method `options' for #<Mongoid::Relations::Metadata:0x000000049dc958> 

任意の考えはどのように私は、カテゴリ名を表示することができますその形で?

EDIT:この1のために<%= lesson_form.association :category %>

:私は、この行を変更した

<%= lesson_form.input :category, :collection => Category.all %>

しかし、フォームをロードしようとしたときに私が取得:残念ながら

Access to the collection for Category is not allowed since it is an embedded document, please access a collection from the root document. 
+0

はい、 'SimpleForm'は' Mongoid'をサポートしていませんが、 'association'の代わりに':collection'オプションを使うことができます –

+0

提案。私はそれを試みましたが、今では別のタイプのエラーが発生します... –

+0

質問自体に編集とエラーを追加しました。 –

答えて

1

SimpleFormはActiveRecord以外のORMをサポートしていません(例えばthis issueを参照)。申し訳ありません、これはあなたの質問に対する非常に良い「答え」ではありません:/

関連する問題