Anna
Anna

Reputation: 203

.save returns false when I try to save in the database

I have this transaction:

begin
  ActiveRecord::Base.transaction do
    route_array.each do |r|
      Rails.logger.info r.save 
    end
  end
end

As you can see I have the route_array and I'm trying to save it in the database, but r.save returns false and I have no clue why. Any idea?

Upvotes: 0

Views: 361

Answers (1)

pierallard
pierallard

Reputation: 3371

The main raison is your model RouteArray has some validations which are not respected.

You can try this code :

 ActiveRecord::Base.transaction do
   route_array.each do |r|
     if !r.valid?
       Rails.logger.info r.errors.inspect
     else
       Rails.logger.info r.save 
     end
   end
 end

Upvotes: 2

Related Questions