diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 00908b1..7a033b3 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -19,9 +19,24 @@ if request.referer == sign_in_url super else - stored_location_for(resource) || request.referer || root_path + stored_location_for(resource) || root_path end - end^ + end + rescue_from CanCan::AccessDenied do |exception| + + if user_signed_in? + flash[:error] = "Not authorized to view this page" + session[:user_return_to] = nil + redirect_to root_url + + else + flash[:error] = "You must first login to view this page" + session[:user_return_to] = request.url + redirect_to "/users/sign_in" + end + + end + def get_theme if ThemesForRails.available_theme_names.include?(params[:theme]) params[:theme] diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb index bc29165..3bda550 100755 --- a/app/views/devise/sessions/new.html.erb +++ b/app/views/devise/sessions/new.html.erb @@ -1,5 +1,14 @@
<%= notice %>
+