Rails Root directory path?

In Rails 3 and newer: Rails.root which returns a Pathname object. If you want a string you have to add .to_s. If you want another path in your Rails app, you can use join like this: Rails.root.join(‘app’, ‘assets’, ‘images’, ‘logo.png’) In Rails 2 you can use the RAILS_ROOT constant, which is a string.

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

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