Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
all the code following along with my post
- Loading branch information
rdonovan
committed
Oct 22, 2010
1 parent
68f1eda
commit 53368ef
Showing
69 changed files
with
4,389 additions
and
310 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class AboutController < ApplicationController | ||
def index | ||
end | ||
|
||
def team | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
class ContentPiecesController < ApplicationController | ||
before_filter :login_required | ||
|
||
def index | ||
@content_pieces = ContentPiece.all | ||
end | ||
|
||
def show | ||
@content_piece = ContentPiece.find(params[:id]) | ||
end | ||
|
||
def new | ||
@content_piece = ContentPiece.new | ||
end | ||
|
||
def create | ||
@content_piece = ContentPiece.new(params[:content_piece]) | ||
if @content_piece.save | ||
flash[:notice] = "Successfully created content piece." | ||
redirect_to @content_piece | ||
else | ||
render :action => 'new' | ||
end | ||
end | ||
|
||
def edit | ||
@content_piece = ContentPiece.find(params[:id]) | ||
end | ||
|
||
def update | ||
@content_piece = ContentPiece.find(params[:id]) | ||
if @content_piece.update_attributes(params[:content_piece]) | ||
flash[:notice] = "Successfully updated content piece." | ||
redirect_to @content_piece | ||
else | ||
render :action => 'edit' | ||
end | ||
end | ||
|
||
def destroy | ||
@content_piece = ContentPiece.find(params[:id]) | ||
@content_piece.destroy | ||
flash[:notice] = "Successfully destroyed content piece." | ||
redirect_to content_pieces_url | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class HomeController < ApplicationController | ||
def index | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class SessionsController < ApplicationController | ||
def new | ||
end | ||
|
||
def create | ||
user = User.authenticate(params[:login], params[:password]) | ||
if user | ||
session[:user_id] = user.id | ||
flash[:notice] = "Logged in successfully." | ||
redirect_to_target_or_default(root_url) | ||
else | ||
flash.now[:error] = "Invalid login or password." | ||
render :action => 'new' | ||
end | ||
end | ||
|
||
def destroy | ||
session[:user_id] = nil | ||
flash[:notice] = "You have been logged out." | ||
redirect_to root_url | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class UsersController < ApplicationController | ||
def new | ||
@user = User.new | ||
end | ||
|
||
def create | ||
@user = User.new(params[:user]) | ||
if @user.save | ||
session[:user_id] = @user.id | ||
flash[:notice] = "Thank you for signing up! You are now logged in." | ||
redirect_to root_url | ||
else | ||
render :action => 'new' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module AboutHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module ContentPiecesHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module HomeHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# These helper methods can be called in your template to set variables to be used in the layout | ||
# This module should be included in all views globally, | ||
# to do so you may need to add this line to your ApplicationController | ||
# helper :layout | ||
module LayoutHelper | ||
def title(page_title, show_title = true) | ||
@content_for_title = page_title.to_s | ||
@show_title = show_title | ||
end | ||
|
||
def show_title? | ||
@show_title | ||
end | ||
|
||
def stylesheet(*args) | ||
content_for(:head) { stylesheet_link_tag(*args) } | ||
end | ||
|
||
def javascript(*args) | ||
content_for(:head) { javascript_include_tag(*args) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module SessionsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module UsersHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class ContentPiece < ActiveRecord::Base | ||
attr_accessible :controller, :view, :area, :content | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
class User < ActiveRecord::Base | ||
# new columns need to be added here to be writable through mass assignment | ||
attr_accessible :username, :email, :password, :password_confirmation | ||
|
||
attr_accessor :password | ||
before_save :prepare_password | ||
|
||
validates_presence_of :username | ||
validates_uniqueness_of :username, :email, :allow_blank => true | ||
validates_format_of :username, :with => /^[-\w\._@]+$/i, :allow_blank => true, :message => "should only contain letters, numbers, or .-_@" | ||
validates_format_of :email, :with => /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i | ||
validates_presence_of :password, :on => :create | ||
validates_confirmation_of :password | ||
validates_length_of :password, :minimum => 4, :allow_blank => true | ||
|
||
# login can be either username or email address | ||
def self.authenticate(login, pass) | ||
user = find_by_username(login) || find_by_email(login) | ||
return user if user && user.matching_password?(pass) | ||
end | ||
|
||
def matching_password?(pass) | ||
self.password_hash == encrypt_password(pass) | ||
end | ||
|
||
private | ||
|
||
def prepare_password | ||
unless password.blank? | ||
self.password_salt = Digest::SHA1.hexdigest([Time.now, rand].join) | ||
self.password_hash = encrypt_password(password) | ||
end | ||
end | ||
|
||
def encrypt_password(pass) | ||
Digest::SHA1.hexdigest([pass, password_salt].join) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
%h1 about us | ||
|
||
:markdown | ||
#{@content_piece_main.content} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
%h1 about our team |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
- form_for @content_piece do |f| | ||
= f.error_messages | ||
%p | ||
= f.label :controller | ||
%br | ||
= f.text_field :controller | ||
%p | ||
= f.label :view | ||
%br | ||
= f.text_field :view | ||
%p | ||
= f.label :area | ||
%br | ||
= f.text_field :area | ||
%p | ||
= f.label :content | ||
%br | ||
= f.text_area :content | ||
%p | ||
= f.submit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
- title "Edit Content Piece" | ||
|
||
= render :partial => 'form' | ||
|
||
%p | ||
= link_to "Show", content_piece_path(@content_piece) | ||
| | ||
= link_to "View All", content_pieces_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
- title "Content Pieces" | ||
|
||
%table | ||
%tr | ||
%th Controller | ||
%th View | ||
%th Area | ||
- for content_piece in @content_pieces | ||
%tr | ||
%td= h content_piece.controller | ||
%td= h content_piece.view | ||
%td= h content_piece.area | ||
%td= link_to 'Show', content_piece | ||
%td= link_to 'Edit', edit_content_piece_path(content_piece) | ||
%td= link_to 'Destroy', content_piece, :confirm => 'Are you sure?', :method => :delete | ||
|
||
%p= link_to "New Content Piece", new_content_piece_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
- title "New Content Piece" | ||
|
||
= render :partial => 'form' | ||
|
||
%p= link_to "Back to List", content_pieces_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
- title "Content Piece" | ||
|
||
%p | ||
%strong Controller: | ||
=h @content_piece.controller | ||
%p | ||
%strong View: | ||
=h @content_piece.view | ||
%p | ||
%strong Area: | ||
=h @content_piece.area | ||
%p | ||
%strong Content: | ||
=h @content_piece.content | ||
|
||
%p | ||
= link_to "Edit", edit_content_piece_path(@content_piece) | ||
| | ||
= link_to "Destroy", @content_piece, :confirm => 'Are you sure?', :method => :delete | ||
| | ||
= link_to "View All", content_pieces_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
= content_for :title do | ||
homepage | ||
|
||
%p this is the homepage text. his is the homepage text. his is the homepage text. his is the homepage text. his is the homepage text. his is the homepage text. his is the homepage text. his is the homepage text. his is the homepage text. his is the homepage text. his is the homepage text. his is the homepage text. his is the homepage text. his is the homepage text. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
!!! Strict | ||
%html{html_attrs} | ||
|
||
%head | ||
%title= h(yield(:title) || "Untitled") | ||
%meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"} | ||
= stylesheet_link_tag 'application' | ||
= yield(:head) | ||
= javascript_include_tag 'application' | ||
%body | ||
#container | ||
#nav | ||
= link_to 'home', root_url | ||
| | ||
= link_to 'about us', '/about' | ||
| | ||
= link_to 'about our team', '/about/team' | ||
| | ||
- if logged_in? | ||
= link_to 'manage content', content_pieces_path | ||
| | ||
= link_to 'logout', '/logout' | ||
- else | ||
= link_to 'login', login_path | ||
- flash.each do |name, msg| | ||
= content_tag :div, msg, :id => "flash_#{name}" | ||
|
||
- if show_title? | ||
%h1=h yield(:title) | ||
|
||
= yield | ||
|
||
= render :partial => '/shared/scripts' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
|
||
%p | ||
Don't have an account? | ||
= link_to "Sign up!", signup_path | ||
|
||
- form_tag sessions_path do | ||
%p | ||
=label_tag :login, "Username or Email Address" | ||
%br | ||
= text_field_tag :login, params[:login] | ||
%p | ||
= label_tag :password | ||
%br | ||
= password_field_tag :password | ||
%p | ||
= submit_tag "Log in" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<script type="text/javascript" src="/javascripts/wmd/wmd.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
= content_for :title do | ||
Sign up | ||
|
||
%p | ||
Already have an account? | ||
= link_to "Log in", login_path | ||
|
||
- form_for @user do |f| | ||
= f.error_messages | ||
%p | ||
= f.label :username | ||
%br | ||
= f.text_field :username | ||
%p | ||
= f.label :email, "Email Address" | ||
%br | ||
= f.text_field :email | ||
%p | ||
= f.label :password | ||
%br | ||
= f.password_field :password | ||
%p | ||
= f.label :password_confirmation, "Confirm Password" | ||
%br | ||
= f.password_field :password_confirmation | ||
%p | ||
= f.submit "Sign up" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.