Skip to content

Instantly share code, notes, and snippets.

@docklandsstudios
Created May 31, 2011 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save docklandsstudios/1000919 to your computer and use it in GitHub Desktop.
Save docklandsstudios/1000919 to your computer and use it in GitHub Desktop.
Redirect Issue
application/controller
class ApplicationController < ActionController::Base
protect_from_forgery
rescue_from CanCan::AccessDenied do |exception|
flash[:alert] = exception.message
redirect_to root_url
end
end
models/user.rb
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable, :lockable and :timeoutable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# New Sign Ups
attr_accessible :email, :password, :password_confirmation, :remember_me, :username
has_and_belongs_to_many :roles
has_many :articles
# ensures usernames are unique and included in sign-up
validates :username, :presence => true, :uniqueness => true
def role?(role)
return !!self.roles.find_by_name(role.to_s)
end
before_create :setup_role
private
def setup_role
if self.role_ids.empty?
self.role_ids = [3]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment