Upgrading Rails: What am I to do with new_framework_defaults file?

(Having just gone through a 4.2 to 5.2 Rails upgrade, I’ll write a more complete answer.) Rails 5.0 Starting with Rails 5, the Rails team decided to generate an initializer, config/initializers/new_framework_defaults.rb, that contained values for new configuration defaults. This file is generated for both new (rails new) Rails 5.0 applications and applications updated (rake app:update) … Read more

Is HTTP status 422 appropriate for records that fail uniqueness validation?

NB: tried to do a detailed answer below poke’s one, but it doesn’t seem to be possible, so I will answer here. I think using 422 for validation errors is fine. The Webdav RFC doesn’t say 422 means “semantic errors”, it says the server was “unable to process the contained instructions” (see https://www.rfc-editor.org/rfc/rfc4918#section-11.2). “Semantic errors” … Read more

postgres ‘psql’ command is not recognized in windows environment

Assuming you installed PostgreSQL on Windows with the PostgreSQL “One-click” installer packaged by EnterpriseDB, psql is not added to the PATH automatically. That’s partly because adding it to the path could otherwise cause confusion when people have multiple versions of PostgreSQL installed. You need to specify the full explicit path to psql, eg: “%PROGRAMFILES%\Postgresql\9.2\bin\psql.exe” or … Read more

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

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