Create a file in your home directory here:
~/.gitconfig

(The dot makes it invisible of course)

In this file, you can configure lots of git stuff:

[user]
email = your-email@your-domain.com
name = John Doe
[diff]
rename = copy

# Always enable color, in all commands
[color]
ui = true
[core]
whitespace=fix,-indent-with-non-tab,trailing-space,cr-at-eol

And if you want some handy aliases for typing less when using git, try these:

[alias]
ba = branch -a
st = status
ca = commit -a -v
ci = commit -v
pl = pull –rebase
pu = push
cmp = gc –aggressive

In your views:

controller.action_name
controller.controller_name

In the controller itself, you can just call

controller_name
action_name

If you want the current URI, try:

request.request_uri

The relative url root is the thing that is appended to the front of your path, but after the domain name, that typically is the unique name of your application. This is often used when you're running more than one app on the same domain.

http://www.somedomain.com/BlogApp
http://www.somedomain.com/EcommerceApp

Rails.configuration.action_controller[:relative_url_root]

Some great shortcuts for script generation. I always try to start by building scaffold for any new entity, then remove the scaffold as needed, leaving only the pieces of the scaffold which I need.

to generate a new model:

script/generate scaffold Person age:integer first:string last:string some_list_id:integer

* This will generate models, controllers, migrations & tests. ALWAYS USE THE SINGULAR when using script/generate.

I'm working with a plugin that I wrote. I want to pull the plugin into an app I'm writing, but still be able to make changes to the plugin and commit those changes back to my repository.

How can I search for available rake tasks?

rake -T | grep gem

(where "gem" is the thing you are searching for)

The above example will return all of the rake tasks relating to gems:

rake gems # List the gems that this rails application depends on
rake gems:build # Build any native extensions for unpacked gems
rake gems:install # Installs all required gems.
rake gems:refresh_specs # Regenerate gem specifications in correct format.
rake gems:unpack # Unpacks all required gems into vendor/gems.
rake gems:unpack:dependencies # Unpacks all required gems and their dependencies into vendor/gems.
rake rails:freeze:gems # Lock this application to the current gems (by unpacking them into vendor/rails)
rake rails:unfreeze # Unlock this application from freeze of gems or edge and return to a fluid use of system gems

Gems are installed by sources, or a repository which holds several gems. Generally all the gems you will need are either in gems.rubyforge.org or gems.github.com, so once you setup these two sources you don't need to setup more sources until you need a gem from somewhere else.

  1. Go to script/console to open ruby in interactive mode. script/console loads your environments (everything in environment.rb and all your plugin and gem initializers), so you basically have access to all your models right from interactive ruby mode (IRB).
  2. Remember use of the p (or its alias puts) command to print stuff to the output buffer. This is useful for testing in IRB mode, inside of a test, or other places where you have an output buffer. If you're running mogrel, your output goes to the terminal. If you're running Passenger with Apache, check your apache error_log for the output.

Sometimes you're in script/console and you make a change to your model files, but since Ruby on reads the models when the environment loads, your change isn't reflected right away in your script/console environment. This will explicitly tell Ruby to reload the environment from scratch. Unfortunately you'll loose any local variables which were assigned too.

script/console reload!
logger.debug WHAT_TO_OUTPUT

***** I think this syntax only works in controllers and outside of a controller you have to use rails_default_debugger ******

(where WHAT_TO_OUTPUT is a string or interpolated to be a string)

The log is in your rails app: log/development.log

© 2012 Tech Notes Suffusion theme by Sayontan Sinha