futzing with cookies in 15.12, although my cookie counter is getting called twice per request... perhaps the "before_filter" method is applied for each filter in a chain?
This commit is contained in:
parent
785c1cfe20
commit
feaea1636c
@ -1,21 +1,28 @@
|
||||
class ApplicationController < ActionController::Base
|
||||
before_filter :set_user
|
||||
before_filter :set_user, :count_visits
|
||||
protect_from_forgery
|
||||
|
||||
private
|
||||
def count_visits
|
||||
value = (cookies[:visits] || '0').to_i
|
||||
cookies[:visits] = (value + 1).to_s
|
||||
@visits = cookies[:visits]
|
||||
end
|
||||
|
||||
protected
|
||||
def set_user
|
||||
@user = User.find(session[:id]) if @user.nil? && session[:id]
|
||||
end
|
||||
def set_user
|
||||
@user = User.find(session[:id]) if @user.nil? && session[:id]
|
||||
end
|
||||
|
||||
def login_required
|
||||
return true if @user
|
||||
access_denied
|
||||
return false
|
||||
end
|
||||
def login_required
|
||||
return true if @user
|
||||
access_denied
|
||||
return false
|
||||
end
|
||||
|
||||
def access_denied
|
||||
session[:return_to] = request.request_uri
|
||||
flash[:error] = 'Oops. You need to login before you can view that page.'
|
||||
redirect_to :controller => 'user', :action => 'login'
|
||||
end
|
||||
def access_denied
|
||||
session[:return_to] = request.request_uri
|
||||
flash[:error] = 'Oops. You need to login before you can view that page.'
|
||||
redirect_to :controller => 'user', :action => 'login'
|
||||
end
|
||||
end
|
||||
|
@ -1,2 +1,4 @@
|
||||
<p>You first visited this site on <%= session[:first_time] %>.</p>
|
||||
<p>That was <%= time_ago_in_words session[:first_time] %> ago.</p>
|
||||
|
||||
<p>You have visited this website's pages <%= @visits %> time(s).</p>
|
||||
|
Loading…
Reference in New Issue
Block a user