mockra

Routing Constraints - 03 May 2012


Here’s what I’m using to redirect visitors to different root_urls depending on whether or not they’re signed in.


class UserConstraint
  def matches?( request )
    !request.cookies['auth_token'].blank?
  end
end

  root to: 'projects#index', constraints:
    UserConstraint.new

  root to: 'users#new'

I’m storing the user’s auth_token in cookies[:auth_token], so you may need to edit the code slightly accordingly.