L.S.,
I have created a rails application which works, I now want to write a
little batch program which uses the different "models" to perform some
tasks. This is what I do:
#!/usr/bin/env ruby
require File.dirname(__FILE__) + ''/../config/environment''
require ''system''
s = System.new( :name => ''a'')
if s.save == false
print "Error saving\n"
exit
end
System is a model, has a field "name" which is unique.
class System < ActiveRecord::Base
validates_uniqueness_of :name
end
When I run the program the second time, I get the "Error saving"
message and the program exits (as expected).
There is no error raised by the save function. If I do no explicit
test, the program just runs on. Is there a way to get better error
handling?
Gr.
Robert
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Alain Ravet
2006-Nov-28 16:56 UTC
Re: Error handling when running outside of web environment
Robert, > There is no error raised by the save function. If I do no explicit > test, the program just runs on. Is there a way to get better error > handling? use save! instead of save http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000906 1397: def save! 1398: save || raise(RecordNotSaved) 1399: end --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks!! New to rails, and ruby but getting into it. gr. Robert --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---