Skip to content
Browse files

Skeloton working with basic user auth.

  • Loading branch information...
1 parent cdfc206 commit 7d62ea26607cc5aa5d46f8c855c0a1f3d0ece28c @robertmilner committed
View
7 app/controllers/application_controller.rb
@@ -4,6 +4,13 @@ class ApplicationController < ActionController::Base
protect_from_forgery
# methods
+ def require_login
+ if session[:user_id].blank?
+ redirect_to root_url, :notice => "You must be signed in to do that."
+ return false
+ end
+ end
+
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
View
1 app/controllers/pages_controller.rb
@@ -1,6 +1,7 @@
class PagesController < ApplicationController
# setting the current user if there is one
+ before_filter :require_login, :except => :excuse
before_filter :current_user
def excuse
View
9 app/views/pages/excuse.html.haml
@@ -8,10 +8,11 @@
- @excuses.each do |excuse|
%li
= excuse.text
- %span
- = form_tag favorites_path do
- = hidden_field_tag :excuse, excuse.id
- = submit_tag "Favorite", :name => nil
+ - if @current_user.present?
+ %span
+ = form_tag favorites_path do
+ = hidden_field_tag :excuse, excuse.id
+ = submit_tag "Favorite", :name => nil
- else
%ul
%li There's no excuse for no excuses! There's only an excuse for Oh, Excuses... Why don't you create one?
View
2 app/views/pages/favorite.html.haml
@@ -4,7 +4,7 @@
= render 'layouts/notice', :notice => notice, :type => "info"
%h2 Your favorites
-- if @favorites.count > 0
+- if @favorites.count > 0 || session[:user_id].blank
%ul
- @favorites.each do |excuse|
%li= excuse.text

0 comments on commit 7d62ea2

Please sign in to comment.
Something went wrong with that request. Please try again.