Change the default value for table column with migration

You have to check which version of ActiveRecord you are using. According to your command rake db:migrate you are still on Ruby on Rails 4.2 or earlier. If you are on ActiveRecord up to 4.2 (change_column_default 4.2.9), there is no from/to option and you can define only the new default option as param. class ChangeDefaultvalueForHideSeasonSelector … Read more

PG::InvalidParameterValue: ERROR: invalid value for parameter “client_min_messages”: “panic”

To make it work with PostgreSQL version 12, I monkey patched PostgreSQLAdapter class to replace ‘panic’ with ‘warning’ message. Note, if you can upgrade activerecord gem to 4.2.6 or higher versions you don’t need to have this monkey patch. I had to do this because my project depends on gem activerecord- require ‘active_record/connection_adapters/postgresql_adapter’ class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter … Read more

Build hash from collection of ActiveRecord Models

Here are some one-liner alternatives: # Ruby 2.1+ name_to_code ={ |c| [,c.code] }.to_h # Ruby 1.8.7+ name_to_code = Hash[{ |c| [,c.code] } ] # Ruby 1.8.6+ name_to_code = Hash[ *{ |c| [,c.code] }.flatten ] # Ruby 1.9+ name_to_code = {}.tap{ |h| countries.each{ |c| h[] = c.code } } # Ruby 1.9+ name_to_code = … Read more