Remember me, devise, and omniauth

This is how you do remember_me with Devise and Omniauthable, this is the OmniauthCallbacksController in one of my apps:

class OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def facebook
    auth(:facebook)
  end

  def twitter
    auth(:twitter)
  end

protected
  def auth(provider)
    auth_hash = request.env['omniauth.auth']
    @user = User.find_for_omniauth(provider, auth_hash, current_user)

    if @user.persisted?
      flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => provider
      @user.remember_me = true
      sign_in_and_redirect @user, :event => :authentication
    else
      session['devise.omniauth'] = auth_hash.except('extra')
      redirect_to new_user_registration_url
    end
  end
end
Advertisements

Postgres.app

Read about Postrgres.app a few weeks ago and I decided to give it a try for my clean install Mountain Lion, turned out it is indeed the easiest (and fastest) way to get PostgreSQL up and running on Mountain Lion.

But when I tried to run psql:

psql: could not connect to server: No such file or directory
 Is the server running locally and accepting
 connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?

You can solve this by running psql -h localhost, but I don’t want to type the host parameter for all the PostgreSQL commands. The solution is to add the following to your .bash_login :

export PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"

Thanks Mattt Thompson and Heroku for creating this wonderful app and I look forward to seeing it up on AppStore.

Ruby and Mountain Lion

Image

This weekend I was trying to do a fresh install of Mountain Lion. This link provides you instructions on how to create a bootable Mountain Lion install disk. If you are going to burn a DVD, you need to make sure you use DVD-DL as normal Mountain Lion won’t fit in the 4.3G DVD.

I use RVM so I installed Xcode and the Command Line Tools. Installing Ruby 1.9.3 with RVM works fine but when I tried to install Ruby 1.8.7, I got:

The autodetected CC(/usr/bin/gcc-4.2) is LLVM based, it is not yet fully supported by ruby and gems, please read `rvm requirements`, and set CC=/path/to/gcc .

The problem is that we need a non-LLVM based gcc compiler. After spending half an hour googling, there are tons of solutions but I found using this homebrew package is easiest:

brew install https://raw.github.com/Homebrew/homebrew-dupes/master/apple-gcc42.rb

You need to install homebrew if you haven’t. I highly recommend you install homebrew as it just makes installing Unix tools so much easier.

The next thing you need to install is XQuartz as X11 is no longer shipped with Mac OS X, so download XQuartz, and run the following to install Ruby 1.8.7:

export CPPFLAGS=-I/opt/X11/include
rvm install 1.8.7

MONEY!

Bonus: MySQL gem 2.8.1

Installing MySQL 2.8.1 gem is just like what you did in Lion, after installing MySQL (I use the 64-bit DMG from MySQL download page), run:

export DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"
env ARCHFLAGS="-arch x86_64" gem install mysql -v='2.8.1' -- --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr/local/mysql/include --with-mysql-config=/usr/local/mysql/bin/mysql_config