Once a month or so, I''d like to pull data from an RSS feed and add it
into my database. I''ve written a rake task that properly reads the
feed, parses it and assigns the correct information to new instances
of my @event model - when I run the rake task and have it print out
the various @event attributes, they''re correct. However, when I
include the command @event.save nothing happens.
In fact, when I added this code
if @event.save
puts "Event saved"
else
puts "Event not saved, bummer"
I got "Event not saved, bummer"
Is it possible to use a rake task to add entries to my application''s
database? If so, any suggestions as to what I might be doing wrong?
I''m testing this in my development environment, and I start my task
definition using
task (:parse_info => :environment) do
Any suggestions would be greatly appreciated. Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Andrew Bloom
2009-Jan-25 23:35 UTC
Re: Help using a rake task to add items to my database?
Try this and see what is printed:
if @event.save
puts "Event saved"
else
puts @event.errors.full_messages.inspect
end
What you''re doing sounds right, most likely though you have a
validation that is keeping the model from saving.
On Jan 25, 4:44 pm, Sharon Machlis
<smach...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Once a month or so, I''d like to pull data from an RSS feed and add
it
> into my database. I''ve written a rake task that properly reads the
> feed, parses it and assigns the correct information to new instances
> of my @event model - when I run the rake task and have it print out
> the various @event attributes, they''re correct. However, when I
> include the command @event.save nothing happens.
>
> In fact, when I added this code
>
> if @event.save
> puts "Event saved"
> else
> puts "Event not saved, bummer"
>
> I got "Event not saved, bummer"
>
> Is it possible to use a rake task to add entries to my
application''s
> database? If so, any suggestions as to what I might be doing wrong?
> I''m testing this in my development environment, and I start my
task
> definition using
>
> task (:parse_info => :environment) do
>
> Any suggestions would be greatly appreciated. Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Patrick Doyle
2009-Jan-26 01:16 UTC
Re: Help using a rake task to add items to my database?
> > What you''re doing sounds right, most likely though you have a > validation that is keeping the model from saving. > > or, possibly a before_filter.--wpd --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sharon Machlis
2009-Jan-26 01:26 UTC
Re: Help using a rake task to add items to my database?
Yes, thank you so much, that''s exactly it! A nil value for one of the attributes was triggering an error, because there''s a validation for a maximum value. I gather a maximum value validation requires there to be a value to check and not nil. Changing that attribute to a string="" for all the entries solved the problem. On Jan 25, 6:35 pm, Andrew Bloom <akbl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Try this and see what is printed: > > if @event.save > puts "Event saved" > else > puts @event.errors.full_messages.inspect > end > > What you''re doing sounds right, most likely though you have a > validation that is keeping the model from saving. > > On Jan 25, 4:44 pm, Sharon Machlis <smach...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Once a month or so, I''d like to pull data from an RSS feed and add it > > into my database. I''ve written a rake task that properly reads the > > feed, parses it and assigns the correct information to new instances > > of my @event model - when I run the rake task and have it print out > > the various @event attributes, they''re correct. However, when I > > include the command @event.save nothing happens. > > > In fact, when I added this code > > > if @event.save > > puts "Event saved" > > else > > puts "Event not saved, bummer" > > > I got "Event not saved, bummer" > > > Is it possible to use a rake task to add entries to my application''s > > database? If so, any suggestions as to what I might be doing wrong? > > I''m testing this in my development environment, and I start my task > > definition using > > > task (:parse_info => :environment) do > > > Any suggestions would be greatly appreciated. Thanks.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---