Excercise: Modularity Consider the following example from the Modularity README: # app/models/article.rb class Article < ActiveRecord::Base include DoesStripFields[:name, :brand] end # app/models/shared/does_strip_fields.rb module DoesStripFields as_trait do |*fields| fields.each do...

Best results in other decks

...on database statements by default, the following query will run for an entire day: ActiveRecord::Base.connection.execute("SELECT pg_sleep(86400)") The good news is that with statement_timeout for PostgreSQL...

...adapter: postgresql # ... variables: statement_timeout: 10s # or ms, min, etc Test that it works: ActiveRecord::Base.connection.execute("show statement_timeout;").map { |row| row } => [{"statement_timeout"=>"10s"}] begin ActiveRecord::Base.connection.execute("SELECT pg...

api.rubyonrails.org

...you have to explicitly tell rails for each transaction to indeed use proper nesting: ActiveRecord::Base.transaction(joinable: false, requires_new: true) do # inner code end This is a safer default...

...this would do meaningful things and only roll back under certain conditions): class Country < ActiveRecord::Base after_save :do_something def do_something raise ActiveRecord::Rollback end end

Search in all decks