PG::ConnectionBad – could not connect to server: Connection refused

It could be as simple as a stale PID file. It could be failing silently because your computer didn’t complete the shutdown process completely which means postgres didn’t delete the PID (process id) file. The PID file is used by postgres to make sure only one instance of the server is running at a time. … Read more

How to find where a method is defined at runtime?

This is really late, but here’s how you can find where a method is defined: http://gist.github.com/76951 # How to find out where a method comes from. # Learned this from Dave Thomas while teaching Advanced Ruby Studio # Makes the case for separating method definitions into # modules, especially when enhancing built-in classes. module Perpetrator … Read more

How to define custom configuration variables in Rails?

In Rails 3, Application specific custom configuration data can be placed in the application configuration object. The configuration can be assigned in the initialization files or the environment files — say for a given application MyApp: MyApp::Application.config.custom_config_variable = :my_config_setting or Rails.configuration.custom_config_variable = :my_config_setting To read the setting, simply call the configuration variable without setting it: … Read more

Using fonts with Rails asset pipeline

If your Rails version is between > 3.1.0 and < 4, place your fonts in any of the these folders: app/assets/fonts lib/assets/fonts vendor/assets/fonts For Rails versions > 4, you must place your fonts in the app/assets/fonts folder. Note: To place fonts outside of these designated folders, use the following configuration: config.assets.precompile << /\.(?:svg|eot|woff|ttf)\z/ For Rails … Read more

Add a reference column migration in Rails 4

Rails 4.x When you already have users and uploads tables and wish to add a new relationship between them. All you need to do is: just generate a migration using the following command: rails g migration AddUserToUploads user:references Which will create a migration file as: class AddUserToUploads < ActiveRecord::Migration def change add_reference :uploads, :user, index: … Read more

@ variables in Ruby on Rails

title is a local variable. They only exists within its scope (current block) @title is an instance variable – and is available to all methods within the class. You can read more here: http://strugglingwithruby.blogspot.dk/2010/03/variables.html In Ruby on Rails – declaring your variables in your controller as instance variables (@title) makes them available to your view.