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 5cd9d97
Show file tree
Hide file tree
Showing 71 changed files with 9,148 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README
@@ -0,0 +1,11 @@
Railscasts Episode #209: Introducing Devise

http://railscasts.com/episodes/209

Commands

bundle install
rails generate devise_install
rails generate devise User
rake db:migrate
rake routes
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
44 changes: 44 additions & 0 deletions todo/app/controllers/projects_controller.rb
@@ -0,0 +1,44 @@
class ProjectsController < ApplicationController
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
33 changes: 33 additions & 0 deletions todo/app/views/layouts/application.html.erb
@@ -0,0 +1,33 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title><%= yield(:title) || "Untitled" %></title>
<%= stylesheet_link_tag 'application' %>
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
<%= yield(:head) %>
</head>
<body>
<div id="container">
<div id="user_nav">
<% if user_signed_in? %>
Signed in as <%= current_user.email %>. Not you?
<%= link_to "Sign out", destroy_user_session_path %>
<% else %>
<%= link_to "Sign up", new_user_registration_path %> or <%= link_to "sign in", new_user_session_path %>
<% end %>
</div>

<% flash.each do |name, msg| %>
<%= content_tag :div, msg, :id => "flash_#{name}" %>
<% end %>
<% if show_title? %>
<h1><%= yield(:title) %></h1>
<% end %>
<%= yield %>
</div>
</body>
</html>
8 changes: 8 additions & 0 deletions todo/app/views/projects/_form.html.erb
@@ -0,0 +1,8 @@
<%= error_messages_for :project %>
<%= form_for @project do |f| %>
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
<p><%= f.submit %></p>
<% end %>
8 changes: 8 additions & 0 deletions todo/app/views/projects/edit.html.erb
@@ -0,0 +1,8 @@
<% title "Edit Project" %>
<%= render :partial => 'form' %>

<p>
<%= link_to "Show", @project %> |
<%= link_to "View All", projects_path %>
</p>
16 changes: 16 additions & 0 deletions todo/app/views/projects/index.html.erb
@@ -0,0 +1,16 @@
<% title "Projects" %>

<table>
<tr>
<th>Name</th>
</tr>
<% for project in @projects %>
<tr>
<td><%= link_to project.name, project %></td>
<td><%= link_to "Edit", edit_project_path(project) %></td>
<td><%= link_to "Destroy", project, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>

<p><%= link_to "New Project", new_project_path %></p>
5 changes: 5 additions & 0 deletions todo/app/views/projects/new.html.erb
@@ -0,0 +1,5 @@
<% title "New Project" %>
<%= render :partial => 'form' %>

<p><%= link_to "Back to List", projects_path %></p>
17 changes: 17 additions & 0 deletions todo/app/views/projects/show.html.erb
@@ -0,0 +1,17 @@
<% title @project.name %>

<h2>Tasks</h2>
<ul>
<% for task in @project.tasks %>
<li>
<%= task.name %>
(<%= link_to "Edit", edit_task_path(task) %> |
<%= link_to "Destroy", task, :confirm => "Are you sure?", :method => :delete %>)
</li>
<% end %>
</ul>

<p>
<%= link_to "New Task", new_task_path(:project_id => @project) %> |
<%= link_to "View All Projects", projects_path %>
</p>
13 changes: 13 additions & 0 deletions todo/app/views/tasks/_form.html.erb
@@ -0,0 +1,13 @@
<%= error_messages_for :task %>
<%= form_for @task do |f| %>
<%= f.hidden_field :project_id %>
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
<p>
<%= f.label :completed_at %><br />
<%= f.date_select :completed_at %>
</p>
<p><%= f.submit %></p>
<% end %>
4 changes: 4 additions & 0 deletions todo/app/views/tasks/edit.html.erb
@@ -0,0 +1,4 @@
<% title "Edit Task" %>
<%= render :partial => 'form' %>

4 changes: 4 additions & 0 deletions todo/app/views/tasks/new.html.erb
@@ -0,0 +1,4 @@
<% title "New Task" %>
<%= render :partial => 'form' %>

4 changes: 4 additions & 0 deletions todo/config.ru
@@ -0,0 +1,4 @@
# This file is used by Rack-based servers to start the application.

require ::File.expand_path('../config/environment', __FILE__)
run Todo::Application
44 changes: 44 additions & 0 deletions todo/config/application.rb
@@ -0,0 +1,44 @@
require File.expand_path('../boot', __FILE__)

require 'rails/all'

# If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env) if defined?(Bundler)

module Todo
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.

# Add additional load paths for your own custom dirs
# config.load_paths += %W( #{config.root}/extras )

# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]

# Activate observers that should always be running
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer

# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'

# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de

# Configure generators values. Many other options are available, be sure to check the documentation.
# config.generators do |g|
# g.orm :active_record
# g.template_engine :erb
# g.test_framework :test_unit, :fixture => true
# end

# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters << :password
config.cookie_secret = '980734b832ad1ba050aeba757e50dcddd47e6a137eaa23286234f6a81504a8fdc818fcbf564ceceb01c2154add61930807a17b8876dfed5c6da98217627202a1'
end
end
14 changes: 14 additions & 0 deletions todo/config/boot.rb
@@ -0,0 +1,14 @@
# Use locked gems if present.
begin
require File.expand_path('../../.bundle/environment', __FILE__)

rescue LoadError
# Otherwise, use RubyGems.
require 'rubygems'

# And set up the gems listed in the Gemfile.
if File.exist?(File.expand_path('../../Gemfile', __FILE__))
require 'bundler'
Bundler.setup
end
end

0 comments on commit 5cd9d97

Please sign in to comment.