Note that there are some explanatory texts on larger screens.

plurals
  1. POIssue with collection_select / mongoid / mongodb
    primarykey
    data
    text
    <p>I am having some trouble with a rails project using mongoid.</p> <p>The problem is when creating/editing a new post.</p> <p>I would like to select a topic/category for post (entertainment/news/ misc).</p> <p>At first I tried the method in railscast 238 (near the end) using a key value</p> <p><a href="http://railscasts.com/episodes/238-mongoid" rel="nofollow">http://railscasts.com/episodes/238-mongoid</a></p> <p>But I kept getting a BSON ObjectID error. While searching for a solution I found topics discussing it, but the fix mentioned is already in the version of mongoid I'm using.</p> <p>So I switched things up. I have no idea if this is good practice or not, but I ran out of ideas. Instead of the railscast method, I used the code below. However, I get this error...</p> <blockquote> <p>"undefined method `metadata' for "4d4165b3fcf1ee14e0000049":String"</p> </blockquote> <pre><code>post model class Post include Mongoid::Document field :link field :title field :synopsis field :added_on, :type =&gt; Date validates_presence_of :link embeds_many :replies embeds_one :topic end topic model class Topic include Mongoid::Document field :category, :type =&gt; String embedded_in :post, :inverse_of =&gt; :topics end </code></pre> <p>&nbsp;</p> <pre><code>_form.html.erb &lt;div class="field"&gt; &lt;%= f.label :topic_id %&gt; &lt;%= f.collection_select :topic, Topic.all, :id, :category, :prompt =&gt; "Select a Topic" %&gt; &lt;/div&gt; </code></pre> <p>I have recently tried changing from embedded_in/embeds_one to references_one/referenced_in. I am also told "Topic.all" is wrong, but I don't know what to change that to to get it to work.</p> <p>Gemfile information...</p> <pre><code>gem "mongoid", "2.0.0.rc.6" gem "bson_ext", "~&gt; 1.2" </code></pre> <p>Anything stick out? </p> <p>Edit:</p> <p>Updated to 2.0.0.rc.7 still can't get it.</p> <p>Tried the key method in the railscast video just for fun. Same "BSON::InvalidObjectId in PostsController#update" error. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload