Starting and stopping Solr

Solr listens to different ports for different environments.

Start Solr (and hide useless output)

rake solr:start PORT=8981 &>/dev/null
rake solr:start PORT=8982 &>/dev/null

Stop Solr

rake solr:stop PORT=8981
rake solr:stop PORT=8982

Run a single Cucumber feature

Run one Cucumber feature file directly with script/cucumber, or invoke it through rake when speed is less important.

Install a gem without RI and RDdoc

Speed up gem installs by skipping RI and RDoc generation with gem install --no-document; a global ~/.gemrc setting can disable local documentation support.

Calling class methods

To call a class method (or static method) from an instance method:

class.method()

To call a class method from a class method:

method()

Fixing "A copy of Klass has been removed from the module tree but is still active"

Development error from mixing non-reloading code with autoloaded classes, often after a stale class reference or cached instance keeps an unloaded constant alive.

Create an application with an older Rails version

sudo gem install rails --version="=1.2.3"
rails _1.2.3_ new-project-folder

Freeze a specific Rails version

sudo apt-get install unzip
rake rails:freeze:edge RELEASE=2.2.2

Show the current Git branch on your Bash prompt

Display the active Git branch directly in the Bash prompt by customizing PS1, so the current repository state is visible while working in the shell.

Run a single test in Test::Unit

Run one Test::Unit file, method, or name-matching subset directly from the command line when a full test suite is unnecessary.

Typical .gitignore

Common ignore list for source control that keeps logs, temporary files, local databases, IDE settings, and generated assets out of git history.

Check out a remote branch in git

Check out a remote branch locally and set up tracking so future pulls and pushes stay linked to origin.

Git for Subversion users

Quick Git commands for former Subversion users who need to clone, stage, commit, push, pull, branch, stash, and restore files.

Test if a checkbox is checked in jQuery

jqueryElement.is(':checked')

Use the ALT key in a VirtualBox Windows VM

ALT input in a VirtualBox Windows VM can feel locked on Ubuntu. Workarounds let the Windows key act as ALT or change key mapping.

Order of the state_machine callback chain

Callback order in state_machine matters when transitions depend on validation and persistence; aborting the chain can stop a transition from completing.

How to fix "Too many authentic authentication failures" with SSH and/or Capistrano

SSH or Capistrano connections can fail when ssh-agent offers too many keys and servers stop after repeated authentication attempts.

Why your all.js is empty on staging or production

When you include a non-existing Javascript file, you probably won't notice it during development. But with caching active (on production or staging) Rails will write an empty all.js file without complaining.

Slugs with FriendlyId

Gem to provide nice looking urls ("/blog/the-greatest-bug-i-never-fixed"). If you don't need anything too special (like i18n for the urls) it works as a drop-in-replacement. It basically overwrites #to_param to return the slug, and .find to search by the slug.

Make sure, everywhere you build paths, you use model_path(:id => model) instead of model_path(:id => model.id). You also need to adapt all code using something like .find_by_id. The regular .find is fine.

See the github README for installation instructions.

Don't forget ...

Copy a Paperclip attachment to another record

Reusing a Paperclip attachment on another record duplicates the file on save; a custom accessor can expose the original URL for form-based copying.

Force absolute URLs in views throughout a response

Relative view helpers generate path-only links and persistent asset hosts; enforcing full URLs needs separate handling for asset_host and rewrite_options.

Unobtrusive JavaScript and AJAX

AJAX-inserted content needs re-running jQuery behavior bindings; $.unobtrusive() scopes activation to new DOM nodes and activateUnobtrusiveJavascript() triggers it manually.

Javascript Compressor - compress code online for free

Reduce JavaScript source size and make code harder to read with a free online compressor for quick minification and obfuscation.

Highlighted prompt for production shells

Insert into ~/.bashrc and reload afterwards: source ~/.bashrc

PS1='${debian_chroot:+($debian_chroot)}\[\033[41;33m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '