Permalink
Browse files

adding episode 253

  • Loading branch information...
1 parent b482bb8 commit ea9ff12efa67f4ec50e119098b6726b64e513b96 @ryanb committed Feb 13, 2011
Showing with 10,308 additions and 0 deletions.
  1. +10 −0 episode-253/README
  2. BIN episode-253/paintings/burney_falls.jpg
  3. BIN episode-253/paintings/crooked_river.jpg
  4. BIN episode-253/paintings/quiet_place.jpg
  5. BIN episode-253/paintings/tree_on_the_bank.jpg
  6. BIN episode-253/paintings/union_creek.jpg
  7. BIN episode-253/paintings/what_lies_beneath.jpg
  8. +5 −0 episode-253/picturesque/.gitignore
  9. +9 −0 episode-253/picturesque/Gemfile
  10. +83 −0 episode-253/picturesque/Gemfile.lock
  11. +7 −0 episode-253/picturesque/Rakefile
  12. +3 −0 episode-253/picturesque/app/controllers/application_controller.rb
  13. +44 −0 episode-253/picturesque/app/controllers/galleries_controller.rb
  14. +36 −0 episode-253/picturesque/app/controllers/paintings_controller.rb
  15. +2 −0 episode-253/picturesque/app/helpers/application_helper.rb
  16. +23 −0 episode-253/picturesque/app/helpers/error_messages_helper.rb
  17. +2 −0 episode-253/picturesque/app/helpers/galleries_helper.rb
  18. +22 −0 episode-253/picturesque/app/helpers/layout_helper.rb
  19. +2 −0 episode-253/picturesque/app/helpers/paintings_helper.rb
  20. +4 −0 episode-253/picturesque/app/models/gallery.rb
  21. +5 −0 episode-253/picturesque/app/models/painting.rb
  22. +47 −0 episode-253/picturesque/app/uploaders/image_uploader.rb
  23. +8 −0 episode-253/picturesque/app/views/galleries/_form.html.erb
  24. +8 −0 episode-253/picturesque/app/views/galleries/edit.html.erb
  25. +10 −0 episode-253/picturesque/app/views/galleries/index.html.erb
  26. +5 −0 episode-253/picturesque/app/views/galleries/new.html.erb
  27. +21 −0 episode-253/picturesque/app/views/galleries/show.html.erb
  28. +19 −0 episode-253/picturesque/app/views/layouts/application.html.erb
  29. +16 −0 episode-253/picturesque/app/views/paintings/_form.html.erb
  30. +5 −0 episode-253/picturesque/app/views/paintings/edit.html.erb
  31. +5 −0 episode-253/picturesque/app/views/paintings/new.html.erb
  32. +4 −0 episode-253/picturesque/config.ru
  33. +42 −0 episode-253/picturesque/config/application.rb
  34. +13 −0 episode-253/picturesque/config/boot.rb
  35. +22 −0 episode-253/picturesque/config/database.yml
  36. +5 −0 episode-253/picturesque/config/environment.rb
  37. +26 −0 episode-253/picturesque/config/environments/development.rb
  38. +49 −0 episode-253/picturesque/config/environments/production.rb
  39. +35 −0 episode-253/picturesque/config/environments/test.rb
  40. +7 −0 episode-253/picturesque/config/initializers/backtrace_silencers.rb
  41. +10 −0 episode-253/picturesque/config/initializers/inflections.rb
  42. +5 −0 episode-253/picturesque/config/initializers/mime_types.rb
  43. +7 −0 episode-253/picturesque/config/initializers/secret_token.rb
  44. +8 −0 episode-253/picturesque/config/initializers/session_store.rb
  45. +5 −0 episode-253/picturesque/config/locales/en.yml
  46. +6 −0 episode-253/picturesque/config/routes.rb
  47. +12 −0 episode-253/picturesque/db/migrate/20110213032730_create_galleries.rb
  48. +13 −0 episode-253/picturesque/db/migrate/20110213032940_create_paintings.rb
  49. +9 −0 episode-253/picturesque/db/migrate/20110213051146_add_image_to_paintings.rb
  50. +29 −0 episode-253/picturesque/db/schema.rb
  51. +7 −0 episode-253/picturesque/db/seeds.rb
  52. +2 −0 episode-253/picturesque/doc/README_FOR_APP
  53. 0 episode-253/picturesque/lib/tasks/.gitkeep
  54. +26 −0 episode-253/picturesque/public/404.html
  55. +26 −0 episode-253/picturesque/public/422.html
  56. +26 −0 episode-253/picturesque/public/500.html
  57. 0 episode-253/picturesque/public/favicon.ico
  58. BIN episode-253/picturesque/public/images/rails.png
  59. +2 −0 episode-253/picturesque/public/javascripts/application.js
  60. +965 −0 episode-253/picturesque/public/javascripts/controls.js
  61. +974 −0 episode-253/picturesque/public/javascripts/dragdrop.js
  62. +1,123 −0 episode-253/picturesque/public/javascripts/effects.js
  63. +6,001 −0 episode-253/picturesque/public/javascripts/prototype.js
  64. +175 −0 episode-253/picturesque/public/javascripts/rails.js
  65. +5 −0 episode-253/picturesque/public/robots.txt
  66. 0 episode-253/picturesque/public/stylesheets/.gitkeep
  67. +106 −0 episode-253/picturesque/public/stylesheets/application.css
  68. +6 −0 episode-253/picturesque/script/rails
  69. +5 −0 episode-253/picturesque/test/fixtures/galleries.yml
  70. +7 −0 episode-253/picturesque/test/fixtures/paintings.yml
  71. +54 −0 episode-253/picturesque/test/functional/galleries_controller_test.rb
  72. +54 −0 episode-253/picturesque/test/functional/paintings_controller_test.rb
  73. +9 −0 episode-253/picturesque/test/performance/browsing_test.rb
  74. +13 −0 episode-253/picturesque/test/test_helper.rb
  75. +7 −0 episode-253/picturesque/test/unit/gallery_test.rb
  76. +7 −0 episode-253/picturesque/test/unit/painting_test.rb
  77. 0 episode-253/picturesque/vendor/plugins/.gitkeep
View
@@ -0,0 +1,10 @@
+Railscasts Episode #253: CarrierWave File Uploads
+
+http://railscasts.com/episodes/253
+
+Commands
+
+ bundle
+ rails g uploader image
+ rails g migration add_image_to_paintings image:string
+ rake db:migrate
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,5 @@
+.bundle
+db/*.sqlite3
+log/*.log
+tmp/**/*
+public/uploads
@@ -0,0 +1,9 @@
+source 'http://rubygems.org'
+
+gem 'rails', '3.0.3'
+gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3'
+gem 'nifty-generators'
+gem 'mocha', :group => :test
+
+gem "rmagick"
+gem "carrierwave"
@@ -0,0 +1,83 @@
+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)
+ arel (2.0.8)
+ builder (2.1.2)
+ carrierwave (0.5.1)
+ activesupport (~> 3.0)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ i18n (0.5.0)
+ mail (2.2.15)
+ activesupport (>= 2.3.6)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.16)
+ mocha (0.9.10)
+ rake
+ nifty-generators (0.4.4)
+ polyglot (0.3.1)
+ rack (1.2.1)
+ rack-mount (0.6.13)
+ rack (>= 1.0.0)
+ rack-test (0.5.7)
+ 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)
+ rmagick (2.13.1)
+ sqlite3-ruby (1.2.5)
+ thor (0.14.6)
+ treetop (1.4.9)
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.24)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ carrierwave
+ mocha
+ nifty-generators
+ rails (= 3.0.3)
+ rmagick
+ sqlite3-ruby (= 1.2.5)
@@ -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'
+
+Picturesque::Application.load_tasks
@@ -0,0 +1,3 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+end
@@ -0,0 +1,44 @@
+class GalleriesController < ApplicationController
+ def index
+ @galleries = Gallery.all
+ end
+
+ def show
+ @gallery = Gallery.find(params[:id])
+ end
+
+ def new
+ @gallery = Gallery.new
+ end
+
+ def create
+ @gallery = Gallery.new(params[:gallery])
+ if @gallery.save
+ flash[:notice] = "Successfully created gallery."
+ redirect_to @gallery
+ else
+ render :action => 'new'
+ end
+ end
+
+ def edit
+ @gallery = Gallery.find(params[:id])
+ end
+
+ def update
+ @gallery = Gallery.find(params[:id])
+ if @gallery.update_attributes(params[:gallery])
+ flash[:notice] = "Successfully updated gallery."
+ redirect_to gallery_url
+ else
+ render :action => 'edit'
+ end
+ end
+
+ def destroy
+ @gallery = Gallery.find(params[:id])
+ @gallery.destroy
+ flash[:notice] = "Successfully destroyed gallery."
+ redirect_to galleries_url
+ end
+end
@@ -0,0 +1,36 @@
+class PaintingsController < ApplicationController
+ def new
+ @painting = Painting.new(:gallery_id => params[:gallery_id])
+ end
+
+ def create
+ @painting = Painting.new(params[:painting])
+ if @painting.save
+ flash[:notice] = "Successfully created painting."
+ redirect_to @painting.gallery
+ else
+ render :action => 'new'
+ end
+ end
+
+ def edit
+ @painting = Painting.find(params[:id])
+ end
+
+ def update
+ @painting = Painting.find(params[:id])
+ if @painting.update_attributes(params[:painting])
+ flash[:notice] = "Successfully updated painting."
+ redirect_to @painting.gallery
+ else
+ render :action => 'edit'
+ end
+ end
+
+ def destroy
+ @painting = Painting.find(params[:id])
+ @painting.destroy
+ flash[:notice] = "Successfully destroyed painting."
+ redirect_to @painting.gallery
+ end
+end
@@ -0,0 +1,2 @@
+module ApplicationHelper
+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,2 @@
+module GalleriesHelper
+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) { h(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 PaintingsHelper
+end
@@ -0,0 +1,4 @@
+class Gallery < ActiveRecord::Base
+ attr_accessible :name
+ has_many :paintings
+end
@@ -0,0 +1,5 @@
+class Painting < ActiveRecord::Base
+ attr_accessible :gallery_id, :name, :image, :remote_image_url
+ belongs_to :gallery
+ mount_uploader :image, ImageUploader
+end
@@ -0,0 +1,47 @@
+# encoding: utf-8
+
+class ImageUploader < CarrierWave::Uploader::Base
+
+ # Include RMagick or ImageScience support:
+ include CarrierWave::RMagick
+ # include CarrierWave::ImageScience
+
+ # Choose what kind of storage to use for this uploader:
+ storage :file
+ # storage :s3
+
+ # Override the directory where uploaded files will be stored.
+ # This is a sensible default for uploaders that are meant to be mounted:
+ def store_dir
+ "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
+ end
+
+ # Provide a default URL as a default if there hasn't been a file uploaded:
+ # def default_url
+ # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
+ # end
+
+ # Process files as they are uploaded:
+ # process :scale => [200, 300]
+ #
+ # def scale(width, height)
+ # # do something
+ # end
+
+ # Create different versions of your uploaded files:
+ version :thumb do
+ process :resize_to_limit => [200, 200]
+ end
+
+ # Add a white list of extensions which are allowed to be uploaded.
+ # For images you might use something like this:
+ # def extension_white_list
+ # %w(jpg jpeg gif png)
+ # end
+
+ # Override the filename of the uploaded files:
+ # def filename
+ # "something.jpg" if original_filename
+ # end
+
+end
@@ -0,0 +1,8 @@
+<%= form_for @gallery do |f| %>
+ <%= f.error_messages %>
+ <p>
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </p>
+ <p><%= f.submit %></p>
+<% end %>
@@ -0,0 +1,8 @@
+<% title "Edit Gallery" %>
+
+<%= render 'form' %>
+
+<p>
+ <%= link_to "Show", @gallery %> |
+ <%= link_to "View All", galleries_path %>
+</p>
@@ -0,0 +1,10 @@
+<% title "Galleries" %>
+
+<% for gallery in @galleries %>
+ <div class="gallery">
+ <h2><%= link_to gallery.name, gallery %></h2>
+ Paintings: <%= gallery.paintings.size %>
+ </div>
+<% end %>
+
+<p><%= link_to "New Gallery", new_gallery_path %></p>
@@ -0,0 +1,5 @@
+<% title "New Gallery" %>
+
+<%= render 'form' %>
+
+<p><%= link_to "Back to List", galleries_path %></p>
@@ -0,0 +1,21 @@
+<% title @gallery.name %>
+
+<div id="paintings">
+ <% for painting in @gallery.paintings %>
+ <div class="painting">
+ <%= image_tag painting.image_url(:thumb) if painting.image? %>
+ <div class="name"><%= painting.name %></div>
+ <div class="actions">
+ <%= link_to "edit", edit_painting_path(painting) %> |
+ <%= link_to "remove", painting, :confirm => 'Are you sure?', :method => :delete %>
+ </div>
+ </div>
+ <% end %>
+ <div class="clear"></div>
+</div>
+
+<p>
+ <%= link_to "Add a Painting", new_painting_path(:gallery_id => @gallery) %> |
+ <%= link_to "Remove Gallery", @gallery, :confirm => 'Are you sure?', :method => :delete %> |
+ <%= link_to "View Galleries", galleries_path %>
+</p>
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title><%= content_for?(:title) ? yield(:title) : "Untitled" %></title>
+ <%= stylesheet_link_tag "application" %>
+ <%= javascript_include_tag :defaults %>
+ <%= csrf_meta_tag %>
+ <%= yield(:head) %>
+ </head>
+ <body>
+ <div id="container">
+ <% flash.each do |name, msg| %>
+ <%= content_tag :div, msg, :id => "flash_#{name}" %>
+ <% end %>
+ <%= content_tag :h1, yield(:title) if show_title? %>
+ <%= yield %>
+ </div>
+ </body>
+</html>
Oops, something went wrong.

0 comments on commit ea9ff12

Please sign in to comment.