Rails - in Rails Console, when you save and get false, How can you find out why?

In Rails Console, I'm creating a record and then entering @record.save and I get false but I can't figure out why? Is there a way in Rails C to output why the save failed?

Thanks

Answers


The errors are accessed through the errors instance method. Example:

ruby-1.8.7-p334 :001 > c = Company.new
=> #<Company id: nil, name: nil, link: nil, created_at: nil, updated_at: nil> 
ruby-1.8.7-p334 :002 > c.save
=> false 
ruby-1.8.7-p334 :003 > c.errors
=> #<OrderedHash {:name=>["can't be blank"]}> 

If it is false then there are errors

In the console type

@record.errors

Need Your Help

HTML5 audio: How to quickly stop and restart a clip?

html5 audio

See title. I am trying to play an audio file 4 times in a row, every 300 milliseconds. However, the clip is longer than 300ms, so it ignores new play requests until the clip is done playing. I'm lo...

Quickest way to find the complement of two collections in C#

c# .net linq complement set-operations

I have two collections of type ICollection&lt;MyType&gt; called c1 and c2. I'd like to find the set of items that are in c2 that are not in c1, where the heuristic for equality is the Id property on