Permalink
Browse files

Merge branch 'master' of https://github.com/ryanb/railscasts-episodes

  • Loading branch information...
2 parents 5f07099 + 746282f commit 3a120ebb5db844b032eff8bb05d75cc49406dbbb @ryanb committed May 9, 2012
Showing with 11,696 additions and 0 deletions.
  1. +16 −0 episode-348/README.md
  2. +15 −0 episode-348/todo-after/.gitignore
  3. +27 −0 episode-348/todo-after/Gemfile
  4. +96 −0 episode-348/todo-after/Gemfile.lock
  5. +9 −0 episode-348/todo-after/README.rdoc
  6. +7 −0 episode-348/todo-after/Rakefile
  7. +18 −0 episode-348/todo-after/api_middleware.txt
  8. +2 −0 episode-348/todo-after/app/controllers/application_controller.rb
  9. +66 −0 episode-348/todo-after/app/controllers/tasks_controller.rb
  10. 0 episode-348/todo-after/app/mailers/.gitkeep
  11. 0 episode-348/todo-after/app/models/.gitkeep
  12. +3 −0 episode-348/todo-after/app/models/task.rb
  13. +2 −0 episode-348/todo-after/app/views/tasks/index.json.rabl
  14. +4 −0 episode-348/todo-after/config.ru
  15. +61 −0 episode-348/todo-after/config/application.rb
  16. +6 −0 episode-348/todo-after/config/boot.rb
  17. +25 −0 episode-348/todo-after/config/database.yml
  18. +5 −0 episode-348/todo-after/config/environment.rb
  19. +37 −0 episode-348/todo-after/config/environments/development.rb
  20. +67 −0 episode-348/todo-after/config/environments/production.rb
  21. +37 −0 episode-348/todo-after/config/environments/test.rb
  22. +7 −0 episode-348/todo-after/config/initializers/backtrace_silencers.rb
  23. +15 −0 episode-348/todo-after/config/initializers/inflections.rb
  24. +5 −0 episode-348/todo-after/config/initializers/mime_types.rb
  25. +7 −0 episode-348/todo-after/config/initializers/secret_token.rb
  26. +8 −0 episode-348/todo-after/config/initializers/session_store.rb
  27. +14 −0 episode-348/todo-after/config/initializers/wrap_parameters.rb
  28. +5 −0 episode-348/todo-after/config/locales/en.yml
  29. +60 −0 episode-348/todo-after/config/routes.rb
  30. +9 −0 episode-348/todo-after/db/migrate/20120508020523_create_tasks.rb
  31. +22 −0 episode-348/todo-after/db/schema.rb
  32. +7 −0 episode-348/todo-after/db/seeds.rb
  33. +2 −0 episode-348/todo-after/doc/README_FOR_APP
  34. +23 −0 episode-348/todo-after/full_middleware.txt
  35. 0 episode-348/todo-after/lib/assets/.gitkeep
  36. 0 episode-348/todo-after/lib/tasks/.gitkeep
  37. 0 episode-348/todo-after/log/.gitkeep
  38. +26 −0 episode-348/todo-after/public/404.html
  39. +26 −0 episode-348/todo-after/public/422.html
  40. +25 −0 episode-348/todo-after/public/500.html
  41. 0 episode-348/todo-after/public/favicon.ico
  42. +52 −0 episode-348/todo-after/public/index.html
  43. +5 −0 episode-348/todo-after/public/robots.txt
  44. +6 −0 episode-348/todo-after/script/rails
  45. 0 episode-348/todo-after/test/fixtures/.gitkeep
  46. +7 −0 episode-348/todo-after/test/fixtures/tasks.yml
  47. 0 episode-348/todo-after/test/functional/.gitkeep
  48. +44 −0 episode-348/todo-after/test/functional/tasks_controller_test.rb
  49. 0 episode-348/todo-after/test/integration/.gitkeep
  50. +12 −0 episode-348/todo-after/test/performance/browsing_test.rb
  51. +13 −0 episode-348/todo-after/test/test_helper.rb
  52. 0 episode-348/todo-after/test/unit/.gitkeep
  53. +7 −0 episode-348/todo-after/test/unit/task_test.rb
  54. 0 episode-348/todo-after/vendor/assets/javascripts/.gitkeep
  55. 0 episode-348/todo-after/vendor/assets/stylesheets/.gitkeep
  56. 0 episode-348/todo-after/vendor/plugins/.gitkeep
  57. +19 −0 episode-349/README.md
  58. +15 −0 episode-349/blog-after/.gitignore
  59. +5 −0 episode-349/blog-after/README.rdoc
  60. +7 −0 episode-349/blog-after/Rakefile
  61. +3 −0 episode-349/blog-after/app/controllers/application_controller.rb
  62. +83 −0 episode-349/blog-after/app/controllers/articles_controller.rb
  63. 0 episode-349/blog-after/app/models/.gitkeep
  64. +48 −0 episode-349/blog-after/app/models/article.rb
  65. +25 −0 episode-349/blog-after/app/views/articles/_form.html.erb
  66. +6 −0 episode-349/blog-after/app/views/articles/edit.html.erb
  67. +25 −0 episode-349/blog-after/app/views/articles/index.html.erb
  68. +5 −0 episode-349/blog-after/app/views/articles/new.html.erb
  69. +15 −0 episode-349/blog-after/app/views/articles/show.html.erb
  70. +14 −0 episode-349/blog-after/app/views/layouts/application.html.erb
  71. +4 −0 episode-349/blog-after/config.ru
  72. +64 −0 episode-349/blog-after/config/application.rb
  73. +6 −0 episode-349/blog-after/config/boot.rb
  74. +5 −0 episode-349/blog-after/config/environment.rb
  75. +37 −0 episode-349/blog-after/config/environments/development.rb
  76. +67 −0 episode-349/blog-after/config/environments/production.rb
  77. +37 −0 episode-349/blog-after/config/environments/test.rb
  78. +60 −0 episode-349/blog-after/config/routes.rb
  79. 0 episode-349/blog-after/log/.gitkeep
  80. +26 −0 episode-349/blog-after/public/404.html
  81. +26 −0 episode-349/blog-after/public/422.html
  82. +25 −0 episode-349/blog-after/public/500.html
  83. 0 episode-349/blog-after/public/favicon.ico
  84. +241 −0 episode-349/blog-after/public/index.html
  85. +9,404 −0 episode-349/blog-after/public/javascripts/jquery.js
  86. +4 −0 episode-349/blog-after/public/javascripts/jquery.min.js
  87. +377 −0 episode-349/blog-after/public/javascripts/jquery_ujs.js
  88. +5 −0 episode-349/blog-after/public/robots.txt
  89. +33 −0 episode-349/blog-after/public/stylesheets/application.css
  90. +6 −0 episode-349/blog-after/script/rails
  91. +4 −0 episode-349/smallapp-after/app/controllers/hello_controller.rb
  92. +1 −0 episode-349/smallapp-after/app/views/hello/world.html.erb
  93. +12 −0 episode-349/smallapp-after/config.ru
  94. +72 −0 episode-349/smallapp-after/log/development.log
View
@@ -0,0 +1,16 @@
+# RailsCasts Episode #348: The Rails API Gem
+
+http://railscasts.com/episodes/348-the-rails-api-gem
+
+Requires Ruby 1.9.2 or higher.
+
+### Commands used in this episode
+
+```
+gem install rails-api
+rbenv rehash
+rails-api new todo
+rails g scaffold task name
+rake middleware
+diff api_middleware.txt full_middleware.txt
+```
@@ -0,0 +1,15 @@
+# See http://help.github.com/ignore-files/ for more about ignoring files.
+#
+# If you find yourself ignoring temporary files generated by your text editor
+# or operating system, you probably want to add a global ignore instead:
+# git config --global core.excludesfile ~/.gitignore_global
+
+# Ignore bundler config
+/.bundle
+
+# Ignore the default SQLite database.
+/db/*.sqlite3
+
+# Ignore all logfiles and tempfiles.
+/log/*.log
+/tmp
@@ -0,0 +1,27 @@
+source 'https://rubygems.org'
+
+gem 'rails', '3.2.3'
+
+# Bundle edge Rails instead:
+# gem 'rails', :git => 'git://github.com/rails/rails.git'
+
+gem 'rails-api'
+
+gem 'sqlite3'
+
+
+# To use ActiveModel has_secure_password
+# gem 'bcrypt-ruby', '~> 3.0.0'
+
+# To use Jbuilder templates for JSON
+# gem 'jbuilder'
+gem 'rabl'
+
+# Use unicorn as the app server
+# gem 'unicorn'
+
+# Deploy with Capistrano
+# gem 'capistrano', :group => :development
+
+# To use debugger
+# gem 'ruby-debug19', :require => 'ruby-debug'
@@ -0,0 +1,96 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ actionmailer (3.2.3)
+ actionpack (= 3.2.3)
+ mail (~> 2.4.4)
+ actionpack (3.2.3)
+ activemodel (= 3.2.3)
+ activesupport (= 3.2.3)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ journey (~> 1.0.1)
+ rack (~> 1.4.0)
+ rack-cache (~> 1.2)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.1.2)
+ activemodel (3.2.3)
+ activesupport (= 3.2.3)
+ builder (~> 3.0.0)
+ activerecord (3.2.3)
+ activemodel (= 3.2.3)
+ activesupport (= 3.2.3)
+ arel (~> 3.0.2)
+ tzinfo (~> 0.3.29)
+ activeresource (3.2.3)
+ activemodel (= 3.2.3)
+ activesupport (= 3.2.3)
+ activesupport (3.2.3)
+ i18n (~> 0.6)
+ multi_json (~> 1.0)
+ arel (3.0.2)
+ builder (3.0.0)
+ erubis (2.7.0)
+ hike (1.2.1)
+ i18n (0.6.0)
+ journey (1.0.3)
+ json (1.7.1)
+ mail (2.4.4)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.18)
+ multi_json (1.3.4)
+ polyglot (0.3.3)
+ rabl (0.6.10)
+ activesupport (>= 2.3.14)
+ multi_json (~> 1.0)
+ rack (1.4.1)
+ rack-cache (1.2)
+ rack (>= 0.4)
+ rack-ssl (1.3.2)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rails (3.2.3)
+ actionmailer (= 3.2.3)
+ actionpack (= 3.2.3)
+ activerecord (= 3.2.3)
+ activeresource (= 3.2.3)
+ activesupport (= 3.2.3)
+ bundler (~> 1.0)
+ railties (= 3.2.3)
+ rails-api (0.0.1)
+ actionpack (>= 3.2.0)
+ railties (>= 3.2.0)
+ tzinfo (~> 0.3.31)
+ railties (3.2.3)
+ actionpack (= 3.2.3)
+ activesupport (= 3.2.3)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (~> 0.14.6)
+ rake (0.9.2.2)
+ rdoc (3.12)
+ json (~> 1.4)
+ sprockets (2.1.3)
+ hike (~> 1.2)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
+ sqlite3 (1.3.6)
+ thor (0.14.6)
+ tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.33)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ rabl
+ rails (= 3.2.3)
+ rails-api
+ sqlite3
@@ -0,0 +1,9 @@
+== Example RailsCasts Application
+
+Run these commands to try it out.
+
+ bundle
+ rake db:setup
+ rails s
+
+Requires Ruby 1.9.2 or later to run.
@@ -0,0 +1,7 @@
+#!/usr/bin/env rake
+# 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__)
+
+Todo::Application.load_tasks
@@ -0,0 +1,18 @@
+use ActionDispatch::Static
+use Rack::Lock
+use #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x007f856197b038>
+use Rack::Runtime
+use ActionDispatch::RequestId
+use Rails::Rack::Logger
+use ActionDispatch::ShowExceptions
+use ActionDispatch::DebugExceptions
+use ActionDispatch::RemoteIp
+use ActionDispatch::Reloader
+use ActionDispatch::Callbacks
+use ActiveRecord::ConnectionAdapters::ConnectionManagement
+use ActiveRecord::QueryCache
+use ActionDispatch::ParamsParser
+use ActionDispatch::Head
+use Rack::ConditionalGet
+use Rack::ETag
+run Todo::Application.routes
@@ -0,0 +1,2 @@
+class ApplicationController < ActionController::API
+end
@@ -0,0 +1,66 @@
+class TasksController < ApplicationController
+ include ActionController::MimeResponds
+ include ActionController::Helpers
+ include ActionController::Cookies
+ include ActionController::ImplicitRender
+
+ # GET /tasks
+ # GET /tasks.json
+ def index
+ @tasks = Task.all
+
+ # respond_to do |format|
+ # format.json { render }
+ # format.xml { render xml: @tasks }
+ # end
+ end
+
+ # GET /tasks/1
+ # GET /tasks/1.json
+ def show
+ @task = Task.find(params[:id])
+
+ render json: @task
+ end
+
+ # GET /tasks/new
+ # GET /tasks/new.json
+ def new
+ @task = Task.new
+
+ render json: @task
+ end
+
+ # POST /tasks
+ # POST /tasks.json
+ def create
+ @task = Task.new(params[:task])
+
+ if @task.save
+ render json: @task, status: :created, location: @task
+ else
+ render json: @task.errors, status: :unprocessable_entity
+ end
+ end
+
+ # PATCH/PUT /tasks/1
+ # PATCH/PUT /tasks/1.json
+ def update
+ @task = Task.find(params[:id])
+
+ if @task.update_attributes(params[:task])
+ head :no_content
+ else
+ render json: @task.errors, status: :unprocessable_entity
+ end
+ end
+
+ # DELETE /tasks/1
+ # DELETE /tasks/1.json
+ def destroy
+ @task = Task.find(params[:id])
+ @task.destroy
+
+ head :no_content
+ end
+end
No changes.
@@ -0,0 +1,3 @@
+class Task < ActiveRecord::Base
+ attr_accessible :name
+end
@@ -0,0 +1,2 @@
+collection @tasks
+attributes :id, :name
@@ -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
@@ -0,0 +1,61 @@
+require File.expand_path('../boot', __FILE__)
+
+require 'rails/all'
+
+if defined?(Bundler)
+ # If you precompile assets before deploying to production, use this line
+ Bundler.require(*Rails.groups(:assets => %w(development test)))
+ # If you want your assets lazily compiled in production, use this line
+ # Bundler.require(:default, :assets, Rails.env)
+end
+
+module Todo
+ class Application < Rails::Application
+ config.middleware.insert_after ActiveRecord::QueryCache, ActionDispatch::Cookies
+
+ # 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.
+
+ # Custom directories with classes and modules you want to be autoloadable.
+ # config.autoload_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 the default encoding used in templates for Ruby 1.9.
+ config.encoding = "utf-8"
+
+ # Configure sensitive parameters which will be filtered from the log file.
+ config.filter_parameters += [:password]
+
+ # Use SQL instead of Active Record's schema dumper when creating the database.
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
+ # like if you have constraints or database-specific column types
+ # config.active_record.schema_format = :sql
+
+ # Enforce whitelist mode for mass assignment.
+ # This will create an empty whitelist of attributes available for mass-assignment for all models
+ # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
+ # parameters by using an attr_accessible or attr_protected declaration.
+ config.active_record.whitelist_attributes = true
+
+ # Enable the asset pipeline
+ config.assets.enabled = true
+
+ # Version of your assets, change this if you want to expire all your assets
+ config.assets.version = '1.0'
+ end
+end
@@ -0,0 +1,6 @@
+require 'rubygems'
+
+# Set up gems listed in the Gemfile.
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
+
+require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,25 @@
+# SQLite version 3.x
+# gem install sqlite3
+#
+# Ensure the SQLite 3 gem is defined in your Gemfile
+# gem 'sqlite3'
+development:
+ adapter: sqlite3
+ database: db/development.sqlite3
+ pool: 5
+ timeout: 5000
+
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+test:
+ adapter: sqlite3
+ database: db/test.sqlite3
+ pool: 5
+ timeout: 5000
+
+production:
+ adapter: sqlite3
+ database: db/production.sqlite3
+ pool: 5
+ timeout: 5000
@@ -0,0 +1,5 @@
+# Load the rails application
+require File.expand_path('../application', __FILE__)
+
+# Initialize the rails application
+Todo::Application.initialize!
Oops, something went wrong.

0 comments on commit 3a120eb

Please sign in to comment.