PostgreSQL + rake db:migrate

ActiveRecord::NoDatabaseError: FATAL: role “dev” does not exist

If you receive the error above when trying to run your Rails migrations against a newly installed instance of PostgreSQL on an Ubuntu development box, all you need to do is a new role to Postgres with the name ‘dev’. Once the role has been added and given the proper permissions, your migrations should run without issue.

 

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

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.

Rails3: Setting up RSpec and Cucumber on Windows

1. Add the following to your ‘Gemfile’ which is located in the root of your application.
———-
# Testing Gems
group :test do
  gem ‘cucumber-rails’, ‘0.3.2’        # BDD testing framework based on Features
  gem ‘capybara’, ‘0.4.1.1’                # Integrations testing for Rack Applications (Rails)
  gem ‘rspec-rails’, ‘2.4.1’                # BDD testing framework
  gem ‘webrat’, ‘0.7.3’                       # Acceptance testing framework
end
———-
2. From a command prompt which has the current path set to the root of your Rails 3 application run the following command. This will install both the cucumber gem as well as the cucumber-rails gem. It will also install RSpec with all of its dependencies as well.
———-
bundle install
———-
3. Now you need to install rspec into your application. By running the rspec generator it will add new folders and files to your basic rails 3 application. In the command prompt where you just executed the previous command you are now going to execute the following command.
———-
rails g rspec:install
———-
4. Setup rspec to create tests automatically by adding a generator to your application.rb file
———-
config.generators do |g|
     g.test_framework :rspec
end
———-
5. Now you need to install cucumber into your application. By running the cucumber generator it will ad new folders and files to your basic rails 3 application. In the command prompt where you just executed the previous command you are now going to execute the following command. (please note the – -rspec and – -capybara are proceeded by two dashes in a row not single dashes.)
———-
rails g cucumber:install –rspec –capybara
———-
6. Now you need to install cucumber into your application. by running the cucumber generator which will add new folders and files to your basic rails 3 application. In the command prompt where you just executed the previous command you are going to execute the following command.
——–
rails g cucumber:install
——–
7. For color coded output on windows within the command prompt you will need to install ANSICON by following the steps below.

  • Download http://adoxa.110mb.com/ansicon/ansi132.zip and unzip it
  • Use a cmd prompt and navigate to where you unzipped it.
  • CD into the x64 directory (unless you have a 32bit machine, then use the x86 one)
  • Type “ansicon.exe –i” (without quotes)
  • Open a new cmd prompt