Hi All... I am trying to parsing data from XML. But, I am not able to store it in database. So, any one can help me out??? Thanks in advance.... -- Posted via http://www.ruby-forum.com/.
2009/9/29 Smit Shah <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > Hi All... > > I am trying to parsing data from XML. But, I am not able to store it in > database. > So, any one can help me out???What is the problem that is preventing you from storing it in the db? Colin
Colin Law wrote:> 2009/9/29 Smit Shah <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>: >> >> Hi All... >> >> I am trying to parsing data from XML. But, I am not able to store it in >> database. >> So, any one can help me out??? > > What is the problem that is preventing you from storing it in the db? > > ColinHi Colin I am using feednormalizer gem. I have written code like @rss = FeedNormalizer::FeedNormalizer.parse open(feed_url) I am accessing the values like "@rss.entries". I have a model named as Data in which I am storing that data. @data = Data.new @data.title = @rss.entries.title But when I try to store in db it shows me like " allocator undefined for Data". Any idea??? -- Posted via http://www.ruby-forum.com/.
2009/9/30 Smit Shah <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > Colin Law wrote: >> 2009/9/29 Smit Shah <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>: >>> >>> Hi All... >>> >>> I am trying to parsing data from XML. But, I am not able to store it in >>> database. >>> So, any one can help me out??? >> >> What is the problem that is preventing you from storing it in the db? >> >> Colin > > Hi Colin > > I am using feednormalizer gem. I have written code like > > @rss = FeedNormalizer::FeedNormalizer.parse open(feed_url) > > I am accessing the values like "@rss.entries". > I have a model named as Data in which I am storing that data. > > @data = Data.new > @data.title = @rss.entries.title > > But when I try to store in db it shows me like " allocator undefined for > Data". > Any idea???Data is a reserved word in rails (see http://wiki.rubyonrails.org/rails/pages/ReservedWords). I suggest using a different name for the model. Colin
Colin Law wrote:> 2009/9/30 Smit Shah <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>: >>> What is the problem that is preventing you from storing it in the db? >> I have a model named as Data in which I am storing that data. >> >> @data = Data.new >> @data.title = @rss.entries.title >> >> But when I try to store in db it shows me like " allocator undefined for >> Data". >> Any idea??? > > Data is a reserved word in rails (see > http://wiki.rubyonrails.org/rails/pages/ReservedWords). I suggest > using a different name for the model. > > ColinHey thanks dude... Its work But now I am suffering from another problem. It stores in db but only the first entry of XML file. I have written that code in for loop. My code is as follow: @rss = FeedNormalizer::FeedNormalizer.parse open(feed_url) @rss = @rss.entries.paginate :page => params[:page], :per_page => 5 if !@rss.blank? @abc = Abc.new for rss in @rss.entries if !@rss.entries.blank? @abc.title = rss.title @abc.url = rss.url end end @abc.save if !@rss.blank? -- Posted via http://www.ruby-forum.com/.
2009/9/30 Preksha Patel <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> But now I am suffering from another problem. It stores in db but only > the first entry of XML file. I have written that code in for loop. My > code is as follow: > > @rss = FeedNormalizer::FeedNormalizer.parse open(feed_url) > @rss = @rss.entries.paginate :page => params[:page], :per_page => 5 if > !@rss.blank? > @abc = Abc.new > for rss in @rss.entries > if !@rss.entries.blank? > -lU24gdL5pOGzQB+pC5nmwQ@public.gmane.org = rss.title > -LVSK5kCdaOk@public.gmane.org = rss.url > end > end > @abc.save if !@rss.blank?Would it be better to have the new and the save inside the loop so that you make a new one and save it for each item? At the moment you make a new object, loop round rewriting the values in @abc each time, then save it once. I presume you realise that the paginate call mean that will only get 5 at a time? Also it might be worthwhile studying the rails guide on Debugging Rails Apps at http://guides.rubyonrails.org/ The techniques there may help you to identify this sort of problem yourself. Colin