ERROR: current transaction aborts, commands are ignored until the end of the transaction block, Ruby on Rails

I have a Car model in my application. I added a color box. My migration is as follows:

class AddColorToCars < ActiveRecord::Migration
  def change
    add_column :cars, :color, :string
    Car.all.each do |car|
      car.color = "silver"
      car.save
    end
  end
end

in my form I add:

= f.input :color

and in the car model I added confirmation:

validates :color, presence: true

When I try to change an existing car and change its color to zero, I have the following error:

ERROR: current transaction is aborted, commands ignored until end of transaction block

When I turn off my check, everything works fine. What's wrong?

+4
source share
1 answer

All this is connected with transactionsin Railswith PostgreSQL.

, PostgreSQL, , .

, . ActiveRecord. - - , INSERT PostgreSQL. , INSERT.

: Rails, .

+9

Source: https://habr.com/ru/post/1542920/


All Articles