Re-namespacing a bit to clear out some fairly old stuff from the top level

This commit is contained in:
Dan Buch
2013-01-22 19:10:10 -05:00
parent ab43fb0146
commit 92f7543872
485 changed files with 0 additions and 0 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,5 @@
class HelloController < ApplicationController
def world
end
end

View File

@@ -0,0 +1,6 @@
class IndexController < ApplicationController
def index
session[:first_time] ||= Time.now
end
end

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,5 @@
class PeopleController < ApplicationController
def list
end
end

View File

@@ -0,0 +1,8 @@
class StatusController < ApplicationController
def index
@title = "System Status"
time = Time.now
@time = time
@ps = `ps aux`
end
end

View File

@@ -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

View File

@@ -0,0 +1,2 @@
module ApplicationHelper
end

View File

@@ -0,0 +1,2 @@
module FooHelper
end

View File

@@ -0,0 +1,2 @@
module IndexHelper
end

View File

@@ -0,0 +1,9 @@
require 'sha1'
module ListHelper
def create_li(item, i)
%{<li class="#{ i % 2 == 0 ? 'even' : 'odd' }">#{i}:
#{SHA1.new(item.object_id.to_s)}</li>}
end
end

View File

@@ -0,0 +1,2 @@
module PeopleHelper
end

View File

@@ -0,0 +1,2 @@
module UserHelper
end

View File

@@ -0,0 +1,2 @@
class Person < ActiveRecord::Base
end

View File

@@ -0,0 +1,32 @@
require 'sha1'
class User < ActiveRecord::Base
attr_accessor :password
attr_protected :hashed_password
validates_uniqueness_of :username
validates_confirmation_of :password, :if => lambda { |user|
user.new_record? or not user.password.blank? }
validates_length_of :password, :within => 5..40, :if => lambda { |user|
user.new_record? or not user.password.blank? }
def self.hashed(str)
SHA1.new(str).to_s
end
def self.authenticate(user_info)
user = find_by_username(user_info[:username])
if user && user.hashed_password == hashed(user_info[:password])
return user
end
end
private
before_save :update_password
def update_password
if not password.blank?
self.hashed_password = self.class.hashed(password)
end
end
end

View File

@@ -0,0 +1,2 @@
<h1>Foo#count</h1>
<p>Find me in app/views/foo/count.html.erb</p>

View File

@@ -0,0 +1,2 @@
<h1>Foo#index</h1>
<p>Find me in app/views/foo/index.html.erb</p>

View File

@@ -0,0 +1,2 @@
<h1>Foo#pretty</h1>
<p>Find me in app/views/foo/pretty.html.erb</p>

View File

@@ -0,0 +1,11 @@
<h1>Several increasingly silly ways of displaying &ldquo;Hello world!&rdquo;:</h1>
<p><%= "Hello world!" %></p>
<p><%= "Hello" + " world!" %></p>
<p><%= w = "world"
"Hello #{w}!" %></p>
<p><%= 'H' + ?e.chr + ('l' * 2) %><%= ('o word!').gsub('d', 'ld')%></p>
<% hello = "Hello" %>
<% world = "world!" %>
<%= hello %> <%= world %>

View File

@@ -0,0 +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&#39;s pages <%= @visits %> time(s).</p>

View File

@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>My Website - <%= @title %></title>
</head>
<body>
<%= yield %>
</body>
</html>

View File

@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>BAR :: My Website - <%= @title %></title>
</head>
<body>
<%= yield %>
</body>
</html>

View File

@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>COUNT :: My Website - <%= @title %></title>
</head>
<body>
<%= yield %>
</body>
</html>

View File

@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>My Pretty Website - <%= @title %></title>
<style type="text/css">
body {
background: #f99;
color: #222;
}
</style>
</head>
<body>
<%= yield %>
</body>
</html>

View File

@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>My Plain Website - <%= @title %></title>
</head>
<body>
<%= yield %>
</body>
</html>

View File

@@ -0,0 +1,4 @@
<%= form_tag :action => 'new' do %>
Item: <%= text_field "item", "value" %>&#x00A;
<%= submit_tag "Add new item" %>
<% end %>

View File

@@ -0,0 +1,5 @@
<ul style="font-family:monospace;">
<% @list.each_with_index do |item, i| %>
<%= create_li(item, i).html_safe %>
<% end %>
</ul>

View File

@@ -0,0 +1,11 @@
<h2>My shopping list</h2>
<ul>
<% @list.each do |item| %>
<li><%= item.name %>
<%= link_to 'Delete', {:action => 'delete', :id => item.id} %>
</li>
<% end %>
</ul>
<%= render :partial => 'new_item_form' %>

View File

@@ -0,0 +1,6 @@
<h1><%= @title %></h1>
<p>I looked up, but saw only the number <%= @counter %></p>
<p>&ldquo;What are you doing here?&rdquo; I asked sharply. &ldquo;Was it
<%= @counter.succ %> who sent you?&rdquo;</p>

View File

@@ -0,0 +1,2 @@
<p>Here they come, the counting numbers,
<%= $one %>, <%= $two %>, <%= $three %>.</p>

View File

@@ -0,0 +1,6 @@
<!-- list.rhtml -->
<ul>
<% Person.find(:all).each do |person| %>
<li>Name: <%= person.name %>, Email: <%= person.email %></li>
<% end %>
</ul>

View File

@@ -0,0 +1,2 @@
<h1>Processes running at <%= @time %></h1>
<pre><%= @ps %></pre>

View File

@@ -0,0 +1,14 @@
<% if @flash %>
<% if @flash[:message] %>
<div id="flash-message"><%= @flash[:message] %></div>
<% end %>
<% if @flash[:error] %>
<div id="flash-error"><%= @flash[:error] %></div>
<% end %>
<% end %>
<%= form_tag :action => 'process_login' do %>
<label for="username">Username:</label> <%= text_field "user", "username" %>&#x00A;
<label for="password">Password:</label> <%= password_field "user", "password" %>&#x00A;
<%= submit_tag %>
<% end %>

View File

@@ -0,0 +1,2 @@
<h1>User#logout</h1>
<p>Find me in app/views/user/logout.html.erb</p>

View File

@@ -0,0 +1,3 @@
<h1>Account Info</h1>
<p>Your username is <%= User.find(session[:id]).username %>

View File

@@ -0,0 +1,2 @@
<h1>User#process_login</h1>
<p>Find me in app/views/user/process_login.html.erb</p>