-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
None
http://stackoverflow.com/questions/20813675/mongoid-saving-only-ids-and-leaving-out-other-fields
Am using Nokogiri and mongoid in a test project here's my code:
urls = Array[ 'http://www.xxx-xxx-xxx.com/cairo', 'http://www.xxx-xxx-xxx.com/alexandria', ] urls.each do |url| doc = Nokogiri::HTML(open(url)) #Theater and location details here #movies scrapper starts here movies = doc.css('.itemContainer') movies.each do |movie| #movie title title = movie.css("h3.catItemTitle a").text #More code here #movie synopsis synopsis = movie.css(".catItemIntroText p").text Movie.create! { {title: title} {synopsis: synopsis } #{movielength: movielength } #embedded theater collection {theaters: {theater: theater, address: address } } } end end
My mongoid models look like this:
require 'mongoid' class Movie include Mongoid::Document field :title, :type => String field :synopsis, :type => String attr_accessible :title, :synopsis embeds_many :theaters end
When i run the nokogiri script only the mongodb objectid gets saved and the field details are not created or saved. Here's a sample of my database.
] }
{ "_id" : ObjectId("52be9b3c4cfad19f0c000011") } { "_id" : ObjectId("52be9b3c4cfad19f0c000012") } { "_id" : ObjectId("52be9b3c4cfad19f0c000013") }has more
Everything works well using ruby "puts" to output but saving in mongodb is a hassle. What am i doing wrong? Am using Mongoid (3.1.6) with ruby 1.9.3p448 on mavericks.