Creating a user token with Devise for other uses except log in into the system

Problem

You are using Devise in your rails application, and you want to have a token for authenticating an API call, but you don’t want to use the default authentication token so that.
The purpose of doing something like that is that you don’t want the application to have the same authentication rights as the devise authentication tokens.

Solution

Add the field to your user model (ie app_token).

On your user model create the following:

class User < ActiveRecord::Base

before_create :create_app_token
...
private
def create_app_token
  self.app_token = Devise.friendly_token
end

Error in staging environment with tr8n and will_filter

Problem
You are using the tr8n translation engine, which works fine in your local development environment, and you want to use it in an environment called ‘staging’, but after deployment you get the following error in your log files;

NoMethodError (undefined method `[]' for nil:NilClass):                                                                                                                                                                                       
  will_filter (3.1.9) lib/will_filter/config.rb:92:in `user_filters_enabled?'                                                                                                                                                                 
  will_filter (3.1.9) lib/will_filter/extensions/action_controller_extension.rb:34:in `init_will_filter'

Solution

The default configuration file for will_filter includes an environment called ‘stage’ and not ‘staging’.
So you can add the following into the config/will_filter/config.yml file in your application (just afer the stage: line):

staging:
  <<: *defaults

Exporting all the commits from git after a certain date

Problem

You would like to export all the commit comments from your git repository into a text file, after a certain date (ie the last live deployment date).

Solution

Use the git log option with the after parameter and redirect the output to a text file like:

git log --after="2012-05-14" --pretty=oneline >> /path/to/file/for/the/commits/export.txt

Some more useful options can be found here