Capistrano: disable deploying to your database server

By default Capistrano will try to deploy your code to whatever server you have set to the :db role, and will try to run the migrations there too.

I’m happy with my database as it is right now so I wanted to disable it.

Here’s how. Just comment out:

before ‘deploy:restart’, ‘deploy:migrate’

or to enable it see:

http://stackoverflow.com/questions/4895450/how-to-modify-capistrano-deploy-to-automatically-run-migrations-in-rails-3-0/4897555

There’s a more complex discussion (with roles) here:

http://wagglelabs.com/2008/09/disable-deploying-to-your-database-server-in-capistrano-2/

If you’re doing a deploy:cold then it automatically runs a db:migrate. So, when you want to do an initial deployment without a migration use:

deploy:update

Bundler Groups

From Katz’ great post:

Specifying groups allows you to do two things. First, you can install the gems in your Gemfile, minus specific groups. For instance, Rails puts mysql and pg in a database group so that if you’re just working on ActionPack, you can bundle install –without db and run the ActionPack tests without having to worry about getting the gems installed.

Second, you can list specific groups to autorequire using Bundler.require. By default, Bundler.require requires all the gems in the default group (which is all the gems that have no explicit group). You can also say Bundler.require(:default, :another_group) to require specific groups.

http://yehudakatz.com/2010/05/09/the-how-and-why-of-bundler-groups/

and

http://stackoverflow.com/questions/3645968/groups-in-a-gemfile-in-rails-3

Bundler.require(*Rails.groups(:assets => %w(development test)))

This line:

  Bundler.require(*Rails.groups(:assets => %w(development test)))

from config/application.rb, i.e. 

if defined?(Bundler)

  # If you precompile assets before deploying to production, use this line

  Bundler.require *Rails.groups(:assets => %w(development test))

  # If you want your assets lazily compiled in production, use this line

  # Bundler.require(:default, :assets, Rails.env)

end

…can look a bit hairy if you’re new to Ruby / Rails.

Breaking it down:

1. The splat operator (*) breaks out the array.

E.g. 

print Rails.groups

[:default, “development”] => nil 

2.0.0p195 :006 > print *Rails.groups

defaultdevelopment => nil 

More on the splat operator here:

http://endofline.wordpress.com/2011/01/21/the-strange-ruby-splat/

2. The %w defines an array

i.e. this 

%w(foo bar) 

is shorthand for an array of strings like this:

[“foo”, “bar”]

http://stackoverflow.com/questions/1274675/ruby-what-does-warray-mean

Note that: %w is slightly different from %W

http://stackoverflow.com/questions/690794/ruby-arrays-w-vs-w?lq=1

3. The colon operator (i.e. :assets) is a symbol

i.e. 

:assets => (“development”, “test”)

Symbols are different from strings in that any two symbols named the same are identical:

“foo”.equal? “foo”  # false

:foo.equal? :foo    # true

http://stackoverflow.com/questions/6337897/what-is-the-colon-operator-in-ruby

——-

Supporting links:

More on how the assets group is handled here:

http://stackoverflow.com/questions/7351607/how-is-the-assets-group-in-rails-3-1-handled-by-bundler

and more on the Rails/Bundler precompile vs lazy compile here:

http://stackoverflow.com/questions/7673988/rails-bundler-precompile-vs-lazy-compile/7675331#7675331

Rails: assets

By default, Rails assumes your assets are precompiled in the production environment. 

And this gives you the best performance.

To check, config.assets.compile should be set to false, e.g.

# config/environments/production.rb

config.assets.compile = false    # don’t compile at runtime. i.e. assets are precompiled

However, you will need to make sure your assets are precompiled. e.g. 

bundle exec rake assets:precompile

A bit of a pain if you have to do it manually. Fortunately, Capistrano has a recipe to handle this at deploy time.

http://stackoverflow.com/questions/7275636/rails-3-1-0-actionviewtemplateerrror-application-css-isnt-precompiled

Notes:

1. you can disable the asset pipeline while creating a new application by passing the —skip-sprockets option

2. You must have an ExecJS supported runtime in order to use CoffeeScript

More on the Asset pipeline here:

http://guides.rubyonrails.org/asset_pipeline.html

Bundler

From the Bundler Getting Started page:

Bundler maintains a consistent environment for ruby applications. It tracks an application’s code and the rubygems it needs to run, so that an application will always have the exact gems (and versions) that it needs to run.

Notes:

1. install 

gem install bundler

2. specify dependencies in the Gemfile

3. install required gems

bundle install 

4. deploying a bundled application

Before deploying an app that uses Bundler, add your Gemfile and Gemfile.lock to source control (but ignore the .bundle folder which is machine-specific)

And then deploy automatically with Capistrano by adding this to your deploy.rb file:

require ‘bundler/capistrano’

For more info, start here:

http://gembundler.com/#getting-started

AutoHotKey alternative for Mac: KeyRemap4MacBook

Complex but powerful.

Don’t use it unless you’re prepared to fiddle with XML and read the docs. 

However, if you’re prepared to put in an hour you’ll reap the benefits – very useful.

Download it from:

https://pqrs.org/macosx/keyremap4macbook/index.html.en

and edit the private.xml using:

Preferences > Misc & Uninstall > Open private.xml

These are handy:

Examples:

https://pqrs.org/macosx/keyremap4macbook/xml.html.en#examples

The Google Group:

https://groups.google.com/forum/#!forum/keyremap4macbook

A sample of how to do a key sequence:

https://raw.github.com/tekezo/Files/master/KeyRemap4MacBook/private.control_d_to_kill_line/private.xml

List of KeyCodes:

https://github.com/tekezo/KeyRemap4MacBook/blob/version_8.3.0/src/bridge/generator/keycode/data/KeyCode.data

List of ModifierFlags:

https://github.com/tekezo/KeyRemap4MacBook/blob/version_8.3.0/src/bridge/generator/keycode/data/ModifierFlag.data

Less handy (unless you want to plough through issues):

https://github.com/tekezo/KeyRemap4MacBook/issues

E.g. to nudge cell contents to the next cell to the right, I use this (replaces Command-X, right cursor, Command-V):

<?xml version=”1.0″?>

<root>

<item>

<name>Excel: Quick Cut and Paste</name>

<identifier>private.excel_cut_paste</identifier>

<autogen>

__KeyToKey__

KeyCode::CURSOR_RIGHT, ModifierFlag::OPTION_L | ModifierFlag::SHIFT_L, 

KeyCode::X, ModifierFlag::COMMAND_L,

KeyCode::CURSOR_RIGHT,

KeyCode::V, ModifierFlag::COMMAND_L,

</autogen>

</item>

</root>

Don’t forget to:

– select your custom shortcut in Preferences > Change Key

– and add it to your Login items

 

AutoHotKey alternative for Mac: KeyRemap4MacBook

Complex but powerful.

Don’t use it unless you’re prepared to fiddle with XML and read the docs. 

However, if you’re prepared to put in an hour you’ll reap the benefits – very useful.

Download it from:

https://pqrs.org/macosx/keyremap4macbook/index.html.en

These are handy:

Examples:

https://pqrs.org/macosx/keyremap4macbook/xml.html.en#examples

The Google Group:

https://groups.google.com/forum/#!forum/keyremap4macbook

A sample of how to do a key sequence:

https://raw.github.com/tekezo/Files/master/KeyRemap4MacBook/private.control_d_to_kill_line/private.xml

List of KeyCodes:

https://github.com/tekezo/KeyRemap4MacBook/blob/version_8.3.0/src/bridge/generator/keycode/data/KeyCode.data

List of ModifierFlags:

https://github.com/tekezo/KeyRemap4MacBook/blob/version_8.3.0/src/bridge/generator/keycode/data/ModifierFlag.data

Less handy (unless you want to plough through issues):

https://github.com/tekezo/KeyRemap4MacBook/issues