Add 'RubyFun/' from commit 'b01c6826131196ba58b5288a3182f2526c89c249'
git-subtree-dir: RubyFun git-subtree-mainline:a04a502787
git-subtree-split:b01c682613
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
class ApplicationController < ActionController::Base
|
||||
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 login_required
|
||||
return true if @user
|
||||
access_denied
|
||||
return false
|
||||
end
|
||||
|
||||
def access_denied
|
||||
session[:return_to] = request.fullpath
|
||||
flash[:error] = 'Oops. You need to login before you can view that page.'
|
||||
redirect_to :controller => 'user', :action => 'login'
|
||||
end
|
||||
end
|
@@ -0,0 +1,18 @@
|
||||
class FooController < ApplicationController
|
||||
layout :figure_out_layout
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
def pretty
|
||||
end
|
||||
|
||||
def figure_out_layout
|
||||
if action_name =~ /pretty/
|
||||
'pretty'
|
||||
else
|
||||
'standard'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@@ -0,0 +1,5 @@
|
||||
class HelloController < ApplicationController
|
||||
def world
|
||||
end
|
||||
|
||||
end
|
@@ -0,0 +1,6 @@
|
||||
class IndexController < ApplicationController
|
||||
def index
|
||||
session[:first_time] ||= Time.now
|
||||
end
|
||||
|
||||
end
|
@@ -0,0 +1,20 @@
|
||||
require 'sha1'
|
||||
|
||||
class ListController < ApplicationController
|
||||
def index
|
||||
@list = [1, "string", :symbol, ['list']]
|
||||
end
|
||||
|
||||
def shopping_list
|
||||
@list = [ListItem.new(4, 'aspirin'), ListItem.new(199, 'succotash')]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
class ListItem
|
||||
attr_accessor :name, :id
|
||||
def initialize(id, name)
|
||||
@id, @name = id, name
|
||||
end
|
||||
end
|
@@ -0,0 +1,25 @@
|
||||
$one = 1
|
||||
|
||||
class NovelController < ApplicationController
|
||||
$two = 2
|
||||
|
||||
def index
|
||||
@title = 'Shattered View: a Novel on Rails'
|
||||
one_plus_one = 1 + 1
|
||||
increment_counter one_plus_one
|
||||
end
|
||||
|
||||
def helper_method
|
||||
@help_message = "I see you've come to me for help."
|
||||
end
|
||||
|
||||
def increment_counter(by)
|
||||
@counter ||= 0
|
||||
@counter += by
|
||||
end
|
||||
|
||||
def sequel
|
||||
$three = 3
|
||||
end
|
||||
|
||||
end
|
@@ -0,0 +1,5 @@
|
||||
class PeopleController < ApplicationController
|
||||
def list
|
||||
end
|
||||
|
||||
end
|
@@ -0,0 +1,8 @@
|
||||
class StatusController < ApplicationController
|
||||
def index
|
||||
@title = "System Status"
|
||||
time = Time.now
|
||||
@time = time
|
||||
@ps = `ps aux`
|
||||
end
|
||||
end
|
@@ -0,0 +1,28 @@
|
||||
class UserController < ApplicationController
|
||||
before_filter :login_required, :only => :my_account
|
||||
|
||||
def login
|
||||
@user = User.new
|
||||
@user.username = params[:username]
|
||||
end
|
||||
|
||||
def process_login
|
||||
if user = User.authenticate(params[:user])
|
||||
session[:id] = user.id
|
||||
redirect_to session[:return_to] || '/'
|
||||
else
|
||||
flash[:error] = 'Invalid login.'
|
||||
redirect_to :action => 'login', :username => params[:user][:username]
|
||||
end
|
||||
end
|
||||
|
||||
def logout
|
||||
reset_session
|
||||
flash[:message] = 'Logged out.'
|
||||
redirect_to :action => 'login'
|
||||
end
|
||||
|
||||
def my_account
|
||||
end
|
||||
|
||||
end
|
Reference in New Issue
Block a user