Permalink
Browse files

automatic import from ryanb/railscasts-episodes

  • Loading branch information...
0 parents commit 32cc7b959aa27888fa78fbbf4f67b36a88d7bfdc @gilesbowkett gilesbowkett committed Jul 29, 2011
Showing with 10,357 additions and 0 deletions.
  1. +9 −0 README
  2. +4 −0 blog/.gitignore
  3. +6 −0 blog/Gemfile
  4. +128 −0 blog/Gemfile.lock
  5. +1 −0 blog/README
  6. +7 −0 blog/Rakefile
  7. +10 −0 blog/app/controllers/application_controller.rb
  8. +45 −0 blog/app/controllers/articles_controller.rb
  9. +15 −0 blog/app/controllers/comments_controller.rb
  10. +13 −0 blog/app/controllers/sessions_controller.rb
  11. +2 −0 blog/app/helpers/application_helper.rb
  12. +2 −0 blog/app/helpers/articles_helper.rb
  13. +2 −0 blog/app/helpers/comments_helper.rb
  14. +23 −0 blog/app/helpers/error_messages_helper.rb
  15. +22 −0 blog/app/helpers/layout_helper.rb
  16. +2 −0 blog/app/helpers/sessions_helper.rb
  17. +4 −0 blog/app/models/article.rb
  18. +4 −0 blog/app/models/comment.rb
  19. +9 −0 blog/app/models/user.rb
  20. +12 −0 blog/app/views/articles/_form.html.erb
  21. +8 −0 blog/app/views/articles/edit.html.erb
  22. +14 −0 blog/app/views/articles/index.html.erb
  23. +5 −0 blog/app/views/articles/new.html.erb
  24. +23 −0 blog/app/views/articles/show.html.erb
  25. +13 −0 blog/app/views/comments/_form.html.erb
  26. +3 −0 blog/app/views/comments/new.html.erb
  27. +27 −0 blog/app/views/layouts/application.html.erb
  28. +4 −0 blog/config.ru
  29. +42 −0 blog/config/application.rb
  30. +13 −0 blog/config/boot.rb
  31. +22 −0 blog/config/database.yml
  32. +5 −0 blog/config/environment.rb
  33. +26 −0 blog/config/environments/development.rb
  34. +49 −0 blog/config/environments/production.rb
  35. +35 −0 blog/config/environments/test.rb
  36. +7 −0 blog/config/initializers/backtrace_silencers.rb
  37. +10 −0 blog/config/initializers/inflections.rb
  38. +5 −0 blog/config/initializers/mime_types.rb
  39. +3 −0 blog/config/initializers/omniauth.rb
  40. +7 −0 blog/config/initializers/secret_token.rb
  41. +8 −0 blog/config/initializers/session_store.rb
  42. +5 −0 blog/config/locales/en.yml
  43. +9 −0 blog/config/routes.rb
  44. +13 −0 blog/db/migrate/20100830033459_create_articles.rb
  45. +14 −0 blog/db/migrate/20100830033648_create_comments.rb
  46. +15 −0 blog/db/migrate/20101122015409_create_users.rb
  47. +38 −0 blog/db/schema.rb
  48. +7 −0 blog/db/seeds.rb
  49. +2 −0 blog/doc/README_FOR_APP
  50. 0 blog/lib/tasks/.gitkeep
  51. +26 −0 blog/public/404.html
  52. +26 −0 blog/public/422.html
  53. +26 −0 blog/public/500.html
  54. 0 blog/public/favicon.ico
  55. +2 −0 blog/public/javascripts/application.js
  56. +965 −0 blog/public/javascripts/controls.js
  57. +974 −0 blog/public/javascripts/dragdrop.js
  58. +1,123 −0 blog/public/javascripts/effects.js
  59. +6,001 −0 blog/public/javascripts/prototype.js
  60. +175 −0 blog/public/javascripts/rails.js
  61. +5 −0 blog/public/robots.txt
  62. 0 blog/public/stylesheets/.gitkeep
  63. +119 −0 blog/public/stylesheets/application.css
  64. +6 −0 blog/script/rails
  65. +7 −0 blog/test/fixtures/articles.yml
  66. +9 −0 blog/test/fixtures/comments.yml
  67. +11 −0 blog/test/fixtures/users.yml
  68. +54 −0 blog/test/functional/articles_controller_test.rb
  69. +20 −0 blog/test/functional/comments_controller_test.rb
  70. +8 −0 blog/test/functional/sessions_controller_test.rb
  71. +9 −0 blog/test/performance/browsing_test.rb
  72. +13 −0 blog/test/test_helper.rb
  73. +7 −0 blog/test/unit/article_test.rb
  74. +7 −0 blog/test/unit/comment_test.rb
  75. +4 −0 blog/test/unit/helpers/sessions_helper_test.rb
  76. +8 −0 blog/test/unit/user_test.rb
  77. 0 blog/vendor/plugins/.gitkeep
9 README
@@ -0,0 +1,9 @@
+Railscasts Episode #241: Simple Omniauth
+
+http://railscasts.com/episodes/241
+
+Commands
+
+ rails g controller sessions
+ rails g model user provider:string uid:string name:string
+ rake db:migrate
@@ -0,0 +1,4 @@
+.bundle
+db/*.sqlite3
+log/*.log
+tmp/**/*
@@ -0,0 +1,6 @@
+source 'http://rubygems.org'
+
+gem 'rails', '3.0.3'
+gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3'
+gem 'nifty-generators'
+gem 'omniauth'
@@ -0,0 +1,128 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ actionmailer (3.0.3)
+ actionpack (= 3.0.3)
+ mail (~> 2.2.9)
+ actionpack (3.0.3)
+ activemodel (= 3.0.3)
+ activesupport (= 3.0.3)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.4)
+ rack (~> 1.2.1)
+ rack-mount (~> 0.6.13)
+ rack-test (~> 0.5.6)
+ tzinfo (~> 0.3.23)
+ activemodel (3.0.3)
+ activesupport (= 3.0.3)
+ builder (~> 2.1.2)
+ i18n (~> 0.4)
+ activerecord (3.0.3)
+ activemodel (= 3.0.3)
+ activesupport (= 3.0.3)
+ arel (~> 2.0.2)
+ tzinfo (~> 0.3.23)
+ activeresource (3.0.3)
+ activemodel (= 3.0.3)
+ activesupport (= 3.0.3)
+ activesupport (3.0.3)
+ addressable (2.2.2)
+ arel (2.0.4)
+ builder (2.1.2)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ faraday (0.5.3)
+ addressable (~> 2.2.2)
+ multipart-post (~> 1.0.1)
+ rack (>= 1.1.0, < 2)
+ i18n (0.4.2)
+ mail (2.2.10)
+ activesupport (>= 2.3.6)
+ i18n (~> 0.4.1)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.16)
+ multi_json (0.0.5)
+ multipart-post (1.0.1)
+ net-ldap (0.1.1)
+ nifty-generators (0.4.2)
+ nokogiri (1.4.4)
+ oa-basic (0.1.6)
+ multi_json (~> 0.0.2)
+ nokogiri (~> 1.4.2)
+ oa-core (= 0.1.6)
+ rest-client (~> 1.6.0)
+ oa-core (0.1.6)
+ rack (~> 1.1)
+ oa-enterprise (0.1.6)
+ net-ldap (~> 0.1.1)
+ nokogiri (~> 1.4.2)
+ oa-core (= 0.1.6)
+ pyu-ruby-sasl (~> 0.0.3.1)
+ rubyntlm (~> 0.1.1)
+ oa-oauth (0.1.6)
+ multi_json (~> 0.0.2)
+ nokogiri (~> 1.4.2)
+ oa-core (= 0.1.6)
+ oauth (~> 0.4.0)
+ oauth2 (~> 0.1.0)
+ oa-openid (0.1.6)
+ oa-core (= 0.1.6)
+ rack-openid (~> 1.2.0)
+ ruby-openid-apps-discovery
+ oauth (0.4.4)
+ oauth2 (0.1.0)
+ faraday (~> 0.5.0)
+ multi_json (~> 0.0.4)
+ omniauth (0.1.6)
+ oa-basic (= 0.1.6)
+ oa-core (= 0.1.6)
+ oa-enterprise (= 0.1.6)
+ oa-oauth (= 0.1.6)
+ oa-openid (= 0.1.6)
+ polyglot (0.3.1)
+ pyu-ruby-sasl (0.0.3.2)
+ rack (1.2.1)
+ rack-mount (0.6.13)
+ rack (>= 1.0.0)
+ rack-openid (1.2.0)
+ rack (>= 1.1.0)
+ ruby-openid (>= 2.1.8)
+ rack-test (0.5.6)
+ rack (>= 1.0)
+ rails (3.0.3)
+ actionmailer (= 3.0.3)
+ actionpack (= 3.0.3)
+ activerecord (= 3.0.3)
+ activeresource (= 3.0.3)
+ activesupport (= 3.0.3)
+ bundler (~> 1.0)
+ railties (= 3.0.3)
+ railties (3.0.3)
+ actionpack (= 3.0.3)
+ activesupport (= 3.0.3)
+ rake (>= 0.8.7)
+ thor (~> 0.14.4)
+ rake (0.8.7)
+ rest-client (1.6.1)
+ mime-types (>= 1.16)
+ ruby-openid (2.1.8)
+ ruby-openid-apps-discovery (1.2.0)
+ ruby-openid (>= 2.1.7)
+ rubyntlm (0.1.1)
+ sqlite3-ruby (1.2.5)
+ thor (0.14.6)
+ treetop (1.4.9)
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.23)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ nifty-generators
+ omniauth
+ rails (= 3.0.3)
+ sqlite3-ruby (= 1.2.5)
@@ -0,0 +1 @@
+Example Railscasts Application
@@ -0,0 +1,7 @@
+# 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'
+
+Blog::Application.load_tasks
@@ -0,0 +1,10 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+ helper_method :current_user
+
+ private
+
+ def current_user
+ @current_user ||= User.find(session[:user_id]) if session[:user_id]
+ end
+end
@@ -0,0 +1,45 @@
+class ArticlesController < ApplicationController
+ def index
+ @articles = Article.all
+ end
+
+ def show
+ @article = Article.find(params[:id])
+ @comment = Comment.new(:article_id => @article.id)
+ end
+
+ def new
+ @article = Article.new
+ end
+
+ def create
+ @article = Article.new(params[:article])
+ if @article.save
+ flash[:notice] = "Successfully created article."
+ redirect_to @article
+ else
+ render :action => 'new'
+ end
+ end
+
+ def edit
+ @article = Article.find(params[:id])
+ end
+
+ def update
+ @article = Article.find(params[:id])
+ if @article.update_attributes(params[:article])
+ flash[:notice] = "Successfully updated article."
+ redirect_to @article
+ else
+ render :action => 'edit'
+ end
+ end
+
+ def destroy
+ @article = Article.find(params[:id])
+ @article.destroy
+ flash[:notice] = "Successfully destroyed article."
+ redirect_to articles_url
+ end
+end
@@ -0,0 +1,15 @@
+class CommentsController < ApplicationController
+ def new
+ @comment = Comment.new
+ end
+
+ def create
+ @comment = Comment.new(params[:comment])
+ if @comment.save
+ flash[:notice] = "Successfully created comment."
+ redirect_to root_url
+ else
+ render :action => 'new'
+ end
+ end
+end
@@ -0,0 +1,13 @@
+class SessionsController < ApplicationController
+ def create
+ auth = request.env["omniauth.auth"]
+ user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.create_with_omniauth(auth)
+ session[:user_id] = user.id
+ redirect_to root_url, :notice => "Signed in!"
+ end
+
+ def destroy
+ session[:user_id] = nil
+ redirect_to root_url, :notice => "Signed out!"
+ end
+end
@@ -0,0 +1,2 @@
+module ApplicationHelper
+end
@@ -0,0 +1,2 @@
+module ArticlesHelper
+end
@@ -0,0 +1,2 @@
+module CommentsHelper
+end
@@ -0,0 +1,23 @@
+module ErrorMessagesHelper
+ # Render error messages for the given objects. The :message and :header_message options are allowed.
+ def error_messages_for(*objects)
+ options = objects.extract_options!
+ options[:header_message] ||= "Invalid Fields"
+ options[:message] ||= "Correct the following errors and try again."
+ messages = objects.compact.map { |o| o.errors.full_messages }.flatten
+ unless messages.empty?
+ content_tag(:div, :class => "error_messages") do
+ list_items = messages.map { |msg| content_tag(:li, msg) }
+ content_tag(:h2, options[:header_message]) + content_tag(:p, options[:message]) + content_tag(:ul, list_items.join.html_safe)
+ end
+ end
+ end
+
+ module FormBuilderAdditions
+ def error_messages(options = {})
+ @template.error_messages_for(@object, options)
+ end
+ end
+end
+
+ActionView::Helpers::FormBuilder.send(:include, ErrorMessagesHelper::FormBuilderAdditions)
@@ -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
@@ -0,0 +1,2 @@
+module SessionsHelper
+end
@@ -0,0 +1,4 @@
+class Article < ActiveRecord::Base
+ attr_accessible :name, :content
+ has_many :comments
+end
@@ -0,0 +1,4 @@
+class Comment < ActiveRecord::Base
+ attr_accessible :article_id, :name, :content
+ belongs_to :article
+end
@@ -0,0 +1,9 @@
+class User < ActiveRecord::Base
+ def self.create_with_omniauth(auth)
+ create! do |user|
+ user.provider = auth["provider"]
+ user.uid = auth["uid"]
+ user.name = auth["user_info"]["name"]
+ end
+ end
+end
@@ -0,0 +1,12 @@
+<%= form_for @article do |f| %>
+ <%= f.error_messages %>
+ <p>
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </p>
+ <p>
+ <%= f.label :content %><br />
+ <%= f.text_area :content %>
+ </p>
+ <p><%= f.submit %></p>
+<% end %>
@@ -0,0 +1,8 @@
+<% title "Edit Article" %>
+
+<%= render 'form' %>
+
+<p>
+ <%= link_to "Show", @article %> |
+ <%= link_to "View All", articles_path %>
+</p>
@@ -0,0 +1,14 @@
+<% title "Articles" %>
+
+<div id="articles">
+<% for article in @articles %>
+ <h2>
+ <%= link_to article.name, article %>
+ <span class="comments">(<%= pluralize(article.comments.size, 'comment') %>)</span>
+ </h2>
+ <div class="created_at">on <%= article.created_at.strftime('%b %d, %Y') %></div>
+ <div class="content"><%= simple_format(article.content) %></div>
+<% end %>
+</div>
+
+<p><%= link_to "New Article", new_article_path %></p>
@@ -0,0 +1,5 @@
+<% title "New Article" %>
+
+<%= render 'form' %>
+
+<p><%= link_to "Back to List", articles_path %></p>
@@ -0,0 +1,23 @@
+<% title @article.name %>
+
+<%= simple_format @article.content %>
+
+<p><%= link_to "Back to Articles", articles_path %></p>
+
+<% unless @article.comments.empty? %>
+ <h2><%= pluralize(@article.comments.size, 'comment') %></h2>
+
+ <div id="comments">
+ <% for comment in @article.comments %>
+ <div class="comment">
+ <strong><%= comment.name %></strong>
+ <em>on <%= comment.created_at.strftime('%b %d, %Y at %I:%M %p') %></em>
+ <%= simple_format comment.content %>
+ </div>
+ <% end %>
+ </div>
+<% end %>
+
+<h3>Add your comment:</h3>
+
+<%= render :partial => 'comments/form' %>
Oops, something went wrong.

0 comments on commit 32cc7b9

Please sign in to comment.