Case-insensitive unique index in Rails/ActiveRecord?

Since MySQL indexes are already case-insensitive, I’m guessing you’re dealing with PostgreSQL, which creates case-sensitive indexes by default. I’m answering here based on Rails 3.2.3 and PostgreSQL 8.4. It seems functional indexes are one more example of things that ActiveRecord can’t generate. Foreign keys and UUID columns are two more that come to mind. So … Read more

Rails Previous Sunday in Relation to Any DateTime

Rails has a convenience method for calculating the beginning of the week. irb(main):001:0> Date.today.beginning_of_week(:sunday) #=> Sun, 16 Dec 2012 See the Date Rails extensions for other possibilities: http://api.rubyonrails.org/classes/Date.html Update: Rails 5.2 adds convenience methods to find the next/previous occurrence of a day. [1] pry(main)> Date.today.prev_occurring(:sunday) #=> Sun, 29 Apr 2018 See the DateAndTime::Calculations documentation for … Read more

Rails: How to raise I18n translation is missing exceptions in the testing environment

As of Rails 4.1.0, there’s now a better solution than the 4 year-old answers to this question: add the following line to your config file: config.action_view.raise_on_missing_translations = true I like to set this in the test environment only, but you might also want to set it in development. I would strongly advise against setting it … Read more

How do I run a migration without starting a transaction in Rails?

There’s now a method disable_ddl_transaction! that allows this, e.g.: class AddIndexesToTablesBasedOnUsage < ActiveRecord::Migration disable_ddl_transaction! def up execute %{ CREATE INDEX CONCURRENTLY index_reservations_subscription_id ON reservations (subscription_id); } end def down execute %{DROP INDEX index_reservations_subscription_id} end end

.gemrc file specification

gem looks for a configuration file .gemrc in your home directory, although you can specify another file on the command-line if you wish (with the –config-file modifier). There are three things you can specify in the configuration file: command-line arguments to be used every time gem runs command-line options for ’’RDoc’’ (used when generating documentation) … Read more

PG::UndefinedTable: ERROR: relation “active_storage_blobs” does not exist

The active_storage_blobs table does not exist yet. You need to first run: rails active_storage:install This command will add 2 migrations for 2 tables: active_storage_attachments and active_storage_blobs. These new migrations need to be run before the migrations you have above. There is a trick for this, you can consider manually changing the timestamp in the filenames … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)