Skip to content

Commit

Permalink
automatic import from ryanb/railscasts-episodes
Browse files Browse the repository at this point in the history
  • Loading branch information
gilesbowkett committed Jul 29, 2011
0 parents commit ec53b5d
Show file tree
Hide file tree
Showing 83 changed files with 9,313 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README
@@ -0,0 +1,10 @@
Railscasts Episode #210: Customizing Devise

http://railscasts.com/episodes/210

Commands

rails generate devise_views
rails generate migration add_username_to_users username:string
rake db:migrate
rails c
4 changes: 4 additions & 0 deletions todo/.gitignore
@@ -0,0 +1,4 @@
.bundle
db/*.sqlite3
log/*.log
tmp/**/*
27 changes: 27 additions & 0 deletions todo/Gemfile
@@ -0,0 +1,27 @@
source 'http://rubygems.org'

gem 'rails', '3.0.0.beta2'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'devise', '1.1.rc0'

# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri', '1.4.1'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'

# Bundle gems for certain environments:
# gem 'rspec', :group => :test
# group :test do
# gem 'webrat'
# end
1 change: 1 addition & 0 deletions todo/README
@@ -0,0 +1 @@
Example rails application used in Railscasts.
10 changes: 10 additions & 0 deletions todo/Rakefile
@@ -0,0 +1,10 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)

require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

Rails::Application.load_tasks
15 changes: 15 additions & 0 deletions todo/app/controllers/application_controller.rb
@@ -0,0 +1,15 @@
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time

# See ActionController::RequestForgeryProtection for details
# Uncomment the :secret if you're not using the cookie session store
protect_from_forgery # :secret => '9ae178eac1fbbd4062a93c8c558a12ef'

# See ActionController::Base for details
# Uncomment this to filter the contents of submitted sensitive data parameters
# from your application log (in this case, all fields with names like "password").
# filter_parameter_logging :password
end
46 changes: 46 additions & 0 deletions todo/app/controllers/projects_controller.rb
@@ -0,0 +1,46 @@
class ProjectsController < ApplicationController
before_filter :authenticate_user!, :except => [:show, :index]

def index
@projects = Project.find(:all)
end

def show
@project = Project.find(params[:id])
end

def new
@project = Project.new
end

def create
@project = Project.new(params[:project])
if @project.save
flash[:notice] = "Successfully created project."
redirect_to @project
else
render :action => 'new'
end
end

def edit
@project = Project.find(params[:id])
end

def update
@project = Project.find(params[:id])
if @project.update_attributes(params[:project])
flash[:notice] = "Successfully updated project."
redirect_to @project
else
render :action => 'edit'
end
end

def destroy
@project = Project.find(params[:id])
@project.destroy
flash[:notice] = "Successfully destroyed project."
redirect_to projects_url
end
end
36 changes: 36 additions & 0 deletions todo/app/controllers/tasks_controller.rb
@@ -0,0 +1,36 @@
class TasksController < ApplicationController
def new
@task = Task.new(:project_id => params[:project_id])
end

def create
@task = Task.new(params[:task])
if @task.save
flash[:notice] = "Successfully created task."
redirect_to @task.project
else
render :action => 'new'
end
end

def edit
@task = Task.find(params[:id])
end

def update
@task = Task.find(params[:id])
if @task.update_attributes(params[:task])
flash[:notice] = "Successfully updated task."
redirect_to @task.project
else
render :action => 'edit'
end
end

def destroy
@task = Task.find(params[:id])
@task.destroy
flash[:notice] = "Successfully destroyed task."
redirect_to @task.project
end
end
3 changes: 3 additions & 0 deletions todo/app/helpers/application_helper.rb
@@ -0,0 +1,3 @@
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
end
23 changes: 23 additions & 0 deletions todo/app/helpers/layout_helper.rb
@@ -0,0 +1,23 @@
# 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.map(&:to_s)) }
end

def javascript(*args)
args = args.map { |arg| arg == :defaults ? arg : arg.to_s }
content_for(:head) { javascript_include_tag(*args) }
end
end
2 changes: 2 additions & 0 deletions todo/app/helpers/projects_helper.rb
@@ -0,0 +1,2 @@
module ProjectsHelper
end
2 changes: 2 additions & 0 deletions todo/app/helpers/tasks_helper.rb
@@ -0,0 +1,2 @@
module TasksHelper
end
3 changes: 3 additions & 0 deletions todo/app/models/project.rb
@@ -0,0 +1,3 @@
class Project < ActiveRecord::Base
has_many :tasks
end
3 changes: 3 additions & 0 deletions todo/app/models/task.rb
@@ -0,0 +1,3 @@
class Task < ActiveRecord::Base
belongs_to :project
end
9 changes: 9 additions & 0 deletions todo/app/models/user.rb
@@ -0,0 +1,9 @@
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :lockable, :timeoutable, :confirmable and :activatable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable

# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation
end
12 changes: 12 additions & 0 deletions todo/app/views/devise/confirmations/new.html.erb
@@ -0,0 +1,12 @@
<h2>Resend confirmation instructions</h2>

<%= form_for(resource_name, resource, :url => confirmation_path(resource_name)) do |f| %>
<%= f.error_messages %>

<p><%= f.label :email %></p>
<p><%= f.text_field :email %></p>

<p><%= f.submit "Resend confirmation instructions" %></p>
<% end %>
<%= render :partial => "devise/shared/links" %>
@@ -0,0 +1,5 @@
<p>Welcome <%= @resource.email %>!</p>

<p>You can confirm your account through the link below:</p>

<p><%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %></p>
@@ -0,0 +1,8 @@
<p>Hello <%= @resource.email %>!</p>

<p>Someone has requested a link to change your password, and you can do this through the link below.</p>

<p><%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %></p>

<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>
7 changes: 7 additions & 0 deletions todo/app/views/devise/mailer/unlock_instructions.html.erb
@@ -0,0 +1,7 @@
<p>Hello <%= @resource.email %>!</p>

<p>Your account has been locked due to an excessive amount of unsuccessful sign in attempts.</p>

<p>Click the link below to unlock your account:</p>

<p><%= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) %></p>
16 changes: 16 additions & 0 deletions todo/app/views/devise/passwords/edit.html.erb
@@ -0,0 +1,16 @@
<h2>Change your password</h2>

<%= form_for(resource_name, resource, :url => password_path(resource_name), :html => { :method => :put }) do |f| %>
<%= f.error_messages %>
<%= f.hidden_field :reset_password_token %>

<p><%= f.label :password %></p>
<p><%= f.password_field :password %></p>

<p><%= f.label :password_confirmation %></p>
<p><%= f.password_field :password_confirmation %></p>

<p><%= f.submit "Change my password" %></p>
<% end %>
<%= render :partial => "devise/shared/links" %>
12 changes: 12 additions & 0 deletions todo/app/views/devise/passwords/new.html.erb
@@ -0,0 +1,12 @@
<h2>Forgot your password?</h2>

<%= form_for(resource_name, resource, :url => password_path(resource_name)) do |f| %>
<%= f.error_messages %>

<p><%= f.label :email %></p>
<p><%= f.text_field :email %></p>

<p><%= f.submit "Send me reset password instructions" %></p>
<% end %>
<%= render :partial => "devise/shared/links" %>
25 changes: 25 additions & 0 deletions todo/app/views/devise/registrations/edit.html.erb
@@ -0,0 +1,25 @@
<h2>Edit <%= resource_name.to_s.humanize %></h2>

<%= form_for(resource_name, resource, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
<%= f.error_messages %>

<p><%= f.label :email %></p>
<p><%= f.text_field :email %></p>

<p><%= f.label :password %> <i>(leave blank if you don't want to change it)</i></p>
<p><%= f.password_field :password %></p>

<p><%= f.label :password_confirmation %></p>
<p><%= f.password_field :password_confirmation %></p>

<p><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i></p>
<p><%= f.password_field :current_password %></p>

<p><%= f.submit "Update" %></p>
<% end %>

<h3>Cancel my account</h3>

<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>.</p>

<%= link_to "Back", :back %>
20 changes: 20 additions & 0 deletions todo/app/views/devise/registrations/new.html.erb
@@ -0,0 +1,20 @@
<h2>Sign up</h2>

<%= form_for(resource_name, resource, :url => registration_path(resource_name)) do |f| %>
<%= f.error_messages %>
<p><%= f.label :username %></p>
<p><%= f.text_field :username %></p>

<p><%= f.label :email %></p>
<p><%= f.text_field :email %></p>

<p><%= f.label :password %></p>
<p><%= f.password_field :password %></p>

<p><%= f.label :password_confirmation %></p>
<p><%= f.password_field :password_confirmation %></p>

<p><%= f.submit "Sign up" %></p>
<% end %>
<%= render :partial => "devise/shared/links" %>
17 changes: 17 additions & 0 deletions todo/app/views/devise/sessions/new.html.erb
@@ -0,0 +1,17 @@
<% title "Sign in" %>
<%= form_for(resource_name, resource, :url => session_path(resource_name)) do |f| %>
<p><%= f.label :username %><br />
<%= f.text_field :username %></p>

<p><%= f.label :password %><br />
<%= f.password_field :password %></p>

<% if devise_mapping.rememberable? -%>
<p><%= f.check_box :remember_me %> <%= f.label :remember_me %></p>
<% end -%>

<p><%= f.submit "Sign in" %></p>
<% end %>
<%= render :partial => "devise/shared/links" %>
19 changes: 19 additions & 0 deletions todo/app/views/devise/shared/_links.erb
@@ -0,0 +1,19 @@
<%- if controller_name != 'sessions' %>
<%= link_to "Sign in", new_session_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
<%= link_to "Sign up", new_registration_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
<%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.lockable? && controller_name != 'unlocks' %>
<%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
<% end -%>
12 changes: 12 additions & 0 deletions todo/app/views/devise/unlocks/new.html.erb
@@ -0,0 +1,12 @@
<h2>Resend unlock instructions</h2>

<%= form_for(resource_name, resource, :url => unlock_path(resource_name)) do |f| %>
<%= f.error_messages %>

<p><%= f.label :email %></p>
<p><%= f.text_field :email %></p>

<p><%= f.submit "Resend unlock instructions" %></p>
<% end %>
<%= render :partial => "devise/shared/links" %>

0 comments on commit ec53b5d

Please sign in to comment.