Rails 4: Set Application-Wide Date/DateTime/Time Display Format

If you are like me, you want the all dates and times to display throughout your application using the same format. This can be accomplished through the following procedure.

Create a new Rails ‘Initializer’ file in your application’s ‘/config/initializers’ directory titled ‘date_format.rb’ and then paste into that file the following Ruby script. Simply uncomment the format you wish to use for each of the types Date, DateTime, and Time.

# Date
# —————————-
#Date::DATE_FORMATS[:default] = “%Y-%m-%d” # 2013-11-03
#Date::DATE_FORMATS[:default] = “%B %e, %Y” # November 3, 2013
#Date::DATE_FORMATS[:default] = “%e %b %Y” # 3 Nov 2013
#Date::DATE_FORMATS[:default] = “%Y%m%d” # 20131103
#Date::DATE_FORMATS[:default] = “%e %b” # 3 Nov

# DateTime
# —————————-
#DateTime::DATE_FORMATS[:default] = “%Y-%m-%d” # 2013-11-03 14:22:18
#DateTime::DATE_FORMATS[:default] = “%B %e, %Y” # November 3, 2013 14:22
#DateTime::DATE_FORMATS[:default] = “%e %b %Y” # Sun, 3 Nov 2013 14:22:18 -0700
#DateTime::DATE_FORMATS[:default] = “%Y%m%d” # 20131103142218
#DateTime::DATE_FORMATS[:default] = “%e %b” # 3 Nov 14:22

# Time
# —————————-
#Time::DATE_FORMATS[:default] = “%Y-%m-%d %H:%M:%S” # 2013-11-03 14:22:18
#Time::DATE_FORMATS[:default] = “%B %d, %Y %H:%M” # November 3, 2013 14:22
#Time::DATE_FORMATS[:default] = “%a, %d %b %Y %H:%M:%S %z” # Sun, 3 Nov 2013 14:22:18 -0700
#Time::DATE_FORMATS[:default] = “%d %b %H:%M” # 3 Nov 14:22
#Time::DATE_FORMATS[:default] = “%Y%m%d%H%M%S” # 20131103142218
#Time::DATE_FORMATS[:default] = “%H:%M” # 14:22

Rails 4: gem install pg (when using the Postgresql App on OS X)

If you are getting a build error from Gem when trying to install the PostgreSQL gem called ‘pg’ and you are using the PostgreSQL App instead of installing PostgreSQL via Brew or some other method, it is because Gem cannot find the PostgreSQL config in the standard locations. To correct this you need to provide Gem with the path to the config file stored within the PostgreSQL App’s internal folder structure.

This can be done as follows:

gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config

<update: for latest versions of Postgres.app>

gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config

Another way to accomplish this is:

export CONFIGURE_ARGS=”with-pg-include=/Applications/Postgres.app/Contents/Versions/9.4/include/”
gem install pg

Note: the latest version of the PostgreSQL App, at the time of this writing was 9.4, your version may be different. Make sure you change the 9.4 in the config path in the command above to the one you are using or it will not work. You can verify the path by opening Finder, going to the Applications folder, locating Postgres.app, right clicking and selecting ‘show package contents’. This will open up the app’s folder structure in Finder.

Mint12 : Heroku Toolbelt – `require’: cannot load such file

If you are running Linux Mint 12 as your Ruby / Rails development environment and you are planning on deploying to Heroku you will need to install Heroku’s Toolbelt in order to execute the commands necessary to create an application in their cloud as well as various other administrative commands.

Heroku provides detailed tutorials to assist you in setting up your environment but as expected they are pretty agnostic when it comes to specific Linux distributions.

For Linux Mint 12 doing the GEM install of the Toolbelt you run the following command and it executes without issue:

gem install heroku foreman

But when you attempt the login command you may get the following error:

heroku login
/rubygems/custom_require.rb:55:in `require': cannot load such file -- readline (LoadError)

I found this was due to a missing gem which is required by either the Heroku Toolbelt or Foreman gems. To correct this issue I installed the ruby readline gem with the following command:

gem install rb-readline

Once the install completed I attempted the Heroku login command again and it was successful.