Permalink
Browse files

automatic import from ryanb/railscasts-episodes

  • Loading branch information...
0 parents commit fc6fce902129195c63a912b1d5932f80d916fccf @gilesbowkett gilesbowkett committed Jul 29, 2011
Showing with 8,558 additions and 0 deletions.
  1. +9 −0 README
  2. +4 −0 blog/.gitignore
  3. +24 −0 blog/Gemfile
  4. +1 −0 blog/README
  5. +10 −0 blog/Rakefile
  6. +3 −0 blog/app/controllers/application_controller.rb
  7. +45 −0 blog/app/controllers/articles_controller.rb
  8. +44 −0 blog/app/controllers/comments_controller.rb
  9. +5 −0 blog/app/helpers/application_helper.rb
  10. +2 −0 blog/app/helpers/articles_helper.rb
  11. +2 −0 blog/app/helpers/comments_helper.rb
  12. +22 −0 blog/app/helpers/layout_helper.rb
  13. +3 −0 blog/app/models/article.rb
  14. +3 −0 blog/app/models/comment.rb
  15. +12 −0 blog/app/views/articles/_form.html.erb
  16. +8 −0 blog/app/views/articles/edit.html.erb
  17. +11 −0 blog/app/views/articles/index.html.erb
  18. +5 −0 blog/app/views/articles/new.html.erb
  19. +18 −0 blog/app/views/articles/show.html.erb
  20. +4 −0 blog/app/views/comments/_comment.html.erb
  21. +17 −0 blog/app/views/comments/_form.html.erb
  22. +8 −0 blog/app/views/comments/edit.html.erb
  23. +21 −0 blog/app/views/comments/index.html.erb
  24. +5 −0 blog/app/views/comments/new.html.erb
  25. +20 −0 blog/app/views/comments/show.html.erb
  26. +22 −0 blog/app/views/layouts/application.html.erb
  27. +4 −0 blog/config.ru
  28. +42 −0 blog/config/application.rb
  29. +17 −0 blog/config/boot.rb
  30. +22 −0 blog/config/database.yml
  31. +5 −0 blog/config/environment.rb
  32. +19 −0 blog/config/environments/development.rb
  33. +33 −0 blog/config/environments/production.rb
  34. +29 −0 blog/config/environments/test.rb
  35. +7 −0 blog/config/initializers/backtrace_silencers.rb
  36. +7 −0 blog/config/initializers/cookie_verification_secret.rb
  37. +10 −0 blog/config/initializers/inflections.rb
  38. +5 −0 blog/config/initializers/mime_types.rb
  39. +15 −0 blog/config/initializers/session_store.rb
  40. +5 −0 blog/config/locales/en.yml
  41. +62 −0 blog/config/routes.rb
  42. +13 −0 blog/db/migrate/20100307004333_create_articles.rb
  43. +15 −0 blog/db/migrate/20100307004441_create_comments.rb
  44. +30 −0 blog/db/schema.rb
  45. +7 −0 blog/db/seeds.rb
  46. +2 −0 blog/doc/README_FOR_APP
  47. 0 blog/lib/tasks/.gitkeep
  48. +26 −0 blog/public/404.html
  49. +26 −0 blog/public/422.html
  50. +26 −0 blog/public/500.html
  51. 0 blog/public/favicon.ico
  52. +2 −0 blog/public/javascripts/application.js
  53. +963 −0 blog/public/javascripts/controls.js
  54. +973 −0 blog/public/javascripts/dragdrop.js
  55. +1,128 −0 blog/public/javascripts/effects.js
  56. +4,320 −0 blog/public/javascripts/prototype.js
  57. +110 −0 blog/public/javascripts/rails.js
  58. +5 −0 blog/public/robots.txt
  59. 0 blog/public/stylesheets/.gitkeep
  60. +113 −0 blog/public/stylesheets/application.css
  61. +10 −0 blog/script/rails
  62. +14 −0 blog/test/fixtures/articles.yml
  63. +21 −0 blog/test/fixtures/comments.yml
  64. +54 −0 blog/test/functional/articles_controller_test.rb
  65. +54 −0 blog/test/functional/comments_controller_test.rb
  66. +9 −0 blog/test/performance/browsing_test.rb
  67. +13 −0 blog/test/test_helper.rb
  68. +7 −0 blog/test/unit/article_test.rb
  69. +7 −0 blog/test/unit/comment_test.rb
  70. 0 blog/vendor/plugins/.gitkeep
9 README
@@ -0,0 +1,9 @@
+Railscasts Episode #204: XSS Protection in Rails 3
+
+http://railscasts.com/episodes/204
+
+Commands
+ rails c
+ "foo".html_safe?
+ safe = "safe".html_safe
+ safe.html_safe?
@@ -0,0 +1,4 @@
+.bundle
+db/*.sqlite3
+log/*.log
+tmp/**/*
@@ -0,0 +1,24 @@
+# Edit this Gemfile to bundle your application's dependencies.
+source 'http://gemcutter.org'
+
+
+gem "rails", "3.0.0.beta"
+
+## Bundle edge rails:
+# gem "rails", :git => "git://github.com/rails/rails.git"
+
+# ActiveRecord requires a database adapter. By default,
+# Rails has selected sqlite3.
+gem "sqlite3-ruby", :require => "sqlite3"
+
+## Bundle the gems you use:
+# gem "bj"
+# gem "hpricot", "0.6"
+# gem "sqlite3-ruby", :require => "sqlite3"
+# gem "aws-s3", :require => "aws/s3"
+
+## Bundle gems used only in certain environments:
+# gem "rspec", :group => :test
+# group :test do
+# gem "webrat"
+# end
@@ -0,0 +1 @@
+Railscasts example application.
@@ -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
@@ -0,0 +1,3 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+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 => @article)
+ 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,44 @@
+class CommentsController < ApplicationController
+ def index
+ @comments = Comment.all
+ end
+
+ def show
+ @comment = Comment.find(params[:id])
+ end
+
+ def new
+ @comment = Comment.new
+ end
+
+ def create
+ @comment = Comment.new(params[:comment])
+ if @comment.save
+ flash[:notice] = "Successfully created comment."
+ redirect_to article_url(@comment.article_id)
+ else
+ render :action => 'new'
+ end
+ end
+
+ def edit
+ @comment = Comment.find(params[:id])
+ end
+
+ def update
+ @comment = Comment.find(params[:id])
+ if @comment.update_attributes(params[:comment])
+ flash[:notice] = "Successfully updated comment."
+ redirect_to @comment
+ else
+ render :action => 'edit'
+ end
+ end
+
+ def destroy
+ @comment = Comment.find(params[:id])
+ @comment.destroy
+ flash[:notice] = "Successfully destroyed comment."
+ redirect_to comments_url
+ end
+end
@@ -0,0 +1,5 @@
+module ApplicationHelper
+ def strong(content)
+ "<strong>#{h(content)}</strong>".html_safe
+ end
+end
@@ -0,0 +1,2 @@
+module ArticlesHelper
+end
@@ -0,0 +1,2 @@
+module CommentsHelper
+end
@@ -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,3 @@
+class Article < ActiveRecord::Base
+ has_many :comments
+end
@@ -0,0 +1,3 @@
+class Comment < ActiveRecord::Base
+ belongs_to :article
+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 "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,11 @@
+<% 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="content"><%= article.content %></div>
+<% end %>
+</div>
@@ -0,0 +1,5 @@
+<% title "New Article" %>
+
+<%= render 'form' %>
+
+<p><%= link_to "Back to List", articles_path %></p>
@@ -0,0 +1,18 @@
+<% title @article.name %>
+
+<p class="author"><em>from <%= @article.name %></em></p>
+
+<%= @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">
+ <%= render @article.comments %>
+ </div>
+<% end %>
+
+<h3>Add your comment:</h3>
+<%= render :partial => 'comments/form' %>
@@ -0,0 +1,4 @@
+<div class="comment">
+ <%= strong link_to(comment.name, comment.url) %>
+ <p><%= comment.content %></p>
+</div>
@@ -0,0 +1,17 @@
+<% form_for @comment do |f| %>
+ <%= f.error_messages %>
+ <%= f.hidden_field :article_id %>
+ <p>
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </p>
+ <p>
+ <%= f.label :url, 'Website URL' %><br />
+ <%= f.text_field :url %>
+ </p>
+ <p>
+ <%= f.label :content, "Comment" %><br />
+ <%= f.text_area :content, :rows => 12, :cols => 35 %>
+ </p>
+ <p><%= f.submit "Submit" %></p>
+<% end %>
@@ -0,0 +1,8 @@
+<% title "Edit Comment" %>
+
+<%= render 'form' %>
+
+<p>
+ <%= link_to "Show", @comment %> |
+ <%= link_to "View All", comments_path %>
+</p>
@@ -0,0 +1,21 @@
+<% title "Comments" %>
+
+<table>
+ <tr>
+ <th>Name</th>
+ <th>URL</th>
+ <th>Content</th>
+ </tr>
+ <% for comment in @comments %>
+ <tr>
+ <td><%= comment.name %></td>
+ <td><%= comment.url %></td>
+ <td><%= comment.content %></td>
+ <td><%= link_to "Show", comment %></td>
+ <td><%= link_to "Edit", edit_comment_path(comment) %></td>
+ <td><%= link_to "Destroy", comment, :confirm => 'Are you sure?', :method => :delete %></td>
+ </tr>
+ <% end %>
+</table>
+
+<p><%= link_to "New Comment", new_comment_path %></p>
@@ -0,0 +1,5 @@
+<% title "New Comment" %>
+
+<%= render 'form' %>
+
+<p><%= link_to "Back to List", comments_path %></p>
@@ -0,0 +1,20 @@
+<% title "Comment" %>
+
+<p>
+ <strong>Name:</strong>
+ <%= @comment.name %>
+</p>
+<p>
+ <strong>URL:</strong>
+ <%= @comment.url %>
+</p>
+<p>
+ <strong>Content:</strong>
+ <%= @comment.content %>
+</p>
+
+<p>
+ <%= link_to "Edit", edit_comment_path(@comment) %> |
+ <%= link_to "Destroy", @comment, :confirm => 'Are you sure?', :method => :delete %> |
+ <%= link_to "View All", comments_path %>
+</p>
@@ -0,0 +1,22 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+ <head>
+ <title><%= h(yield(:title) || "Untitled") %></title>
+ <%= stylesheet_link_tag 'application' %>
+ <%= yield(:head) %>
+ </head>
+ <body>
+ <div id="container">
+ <%- flash.each do |name, msg| -%>
+ <%= content_tag :div, msg, :id => "flash_#{name}" %>
+ <%- end -%>
+
+ <%- if show_title? -%>
+ <h1><%=h yield(:title) %></h1>
+ <%- end -%>
+
+ <%= yield %>
+ </div>
+ </body>
+</html>
@@ -0,0 +1,4 @@
+# This file is used by Rack-based servers to start the application.
+
+require ::File.expand_path('../config/environment', __FILE__)
+run Blog::Application
Oops, something went wrong.

0 comments on commit fc6fce9

Please sign in to comment.