Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
automatic import from ryanb/railscasts-episodes
- Loading branch information
0 parents
commit ec53b5d
Showing
83 changed files
with
9,313 additions
and
0 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,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 |
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 @@ | ||
.bundle | ||
db/*.sqlite3 | ||
log/*.log | ||
tmp/**/* |
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,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 |
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 @@ | ||
Example rails application used in Railscasts. |
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,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 |
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,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 |
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 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 |
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,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 |
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 @@ | ||
# Methods added to this helper will be available to all templates in the application. | ||
module ApplicationHelper | ||
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,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 |
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 ProjectsHelper | ||
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 TasksHelper | ||
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 Project < ActiveRecord::Base | ||
has_many :tasks | ||
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 Task < ActiveRecord::Base | ||
belongs_to :project | ||
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,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 |
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,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" %> |
5 changes: 5 additions & 0 deletions
5
todo/app/views/devise/mailer/confirmation_instructions.html.erb
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 @@ | ||
<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> |
8 changes: 8 additions & 0 deletions
8
todo/app/views/devise/mailer/reset_password_instructions.html.erb
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 @@ | ||
<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> |
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,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> |
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 @@ | ||
<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" %> |
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,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" %> |
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,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 %> |
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 @@ | ||
<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" %> |
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 "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" %> |
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,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 -%> |
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,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" %> |
Oops, something went wrong.