Permalink
Browse files

adding episode 273

  • Loading branch information...
1 parent 1e477d1 commit 66b49e603db18fc91265c1f0878da01237cfff19 @ryanb committed Jul 4, 2011
Showing with 20,077 additions and 0 deletions.
  1. +8 −0 episode-273/README
  2. +4 −0 episode-273/siteseer-after/.gitignore
  3. +7 −0 episode-273/siteseer-after/Gemfile
  4. +79 −0 episode-273/siteseer-after/Gemfile.lock
  5. +7 −0 episode-273/siteseer-after/README
  6. +7 −0 episode-273/siteseer-after/Rakefile
  7. +3 −0 episode-273/siteseer-after/app/controllers/application_controller.rb
  8. +45 −0 episode-273/siteseer-after/app/controllers/locations_controller.rb
  9. +2 −0 episode-273/siteseer-after/app/helpers/application_helper.rb
  10. +23 −0 episode-273/siteseer-after/app/helpers/error_messages_helper.rb
  11. +22 −0 episode-273/siteseer-after/app/helpers/layout_helper.rb
  12. +2 −0 episode-273/siteseer-after/app/helpers/locations_helper.rb
  13. +5 −0 episode-273/siteseer-after/app/models/location.rb
  14. +19 −0 episode-273/siteseer-after/app/views/layouts/application.html.erb
  15. +16 −0 episode-273/siteseer-after/app/views/locations/_form.html.erb
  16. +8 −0 episode-273/siteseer-after/app/views/locations/edit.html.erb
  17. +28 −0 episode-273/siteseer-after/app/views/locations/index.html.erb
  18. +5 −0 episode-273/siteseer-after/app/views/locations/new.html.erb
  19. +29 −0 episode-273/siteseer-after/app/views/locations/show.html.erb
  20. +4 −0 episode-273/siteseer-after/config.ru
  21. +42 −0 episode-273/siteseer-after/config/application.rb
  22. +6 −0 episode-273/siteseer-after/config/boot.rb
  23. +22 −0 episode-273/siteseer-after/config/database.yml
  24. +5 −0 episode-273/siteseer-after/config/environment.rb
  25. +26 −0 episode-273/siteseer-after/config/environments/development.rb
  26. +49 −0 episode-273/siteseer-after/config/environments/production.rb
  27. +35 −0 episode-273/siteseer-after/config/environments/test.rb
  28. +7 −0 episode-273/siteseer-after/config/initializers/backtrace_silencers.rb
  29. +10 −0 episode-273/siteseer-after/config/initializers/inflections.rb
  30. +5 −0 episode-273/siteseer-after/config/initializers/mime_types.rb
  31. +7 −0 episode-273/siteseer-after/config/initializers/secret_token.rb
  32. +8 −0 episode-273/siteseer-after/config/initializers/session_store.rb
  33. +5 −0 episode-273/siteseer-after/config/locales/en.yml
  34. +60 −0 episode-273/siteseer-after/config/routes.rb
  35. +14 −0 episode-273/siteseer-after/db/migrate/20110704040959_create_locations.rb
  36. +23 −0 episode-273/siteseer-after/db/schema.rb
  37. +7 −0 episode-273/siteseer-after/db/seeds.rb
  38. +2 −0 episode-273/siteseer-after/doc/README_FOR_APP
  39. 0 episode-273/siteseer-after/lib/tasks/.gitkeep
  40. +26 −0 episode-273/siteseer-after/public/404.html
  41. +26 −0 episode-273/siteseer-after/public/422.html
  42. +26 −0 episode-273/siteseer-after/public/500.html
  43. 0 episode-273/siteseer-after/public/favicon.ico
  44. BIN episode-273/siteseer-after/public/images/rails.png
  45. +2 −0 episode-273/siteseer-after/public/javascripts/application.js
  46. +965 −0 episode-273/siteseer-after/public/javascripts/controls.js
  47. +974 −0 episode-273/siteseer-after/public/javascripts/dragdrop.js
  48. +1,123 −0 episode-273/siteseer-after/public/javascripts/effects.js
  49. +6,001 −0 episode-273/siteseer-after/public/javascripts/prototype.js
  50. +191 −0 episode-273/siteseer-after/public/javascripts/rails.js
  51. +5 −0 episode-273/siteseer-after/public/robots.txt
  52. 0 episode-273/siteseer-after/public/stylesheets/.gitkeep
  53. +75 −0 episode-273/siteseer-after/public/stylesheets/application.css
  54. +6 −0 episode-273/siteseer-after/script/rails
  55. +9 −0 episode-273/siteseer-after/test/fixtures/locations.yml
  56. +54 −0 episode-273/siteseer-after/test/functional/locations_controller_test.rb
  57. +9 −0 episode-273/siteseer-after/test/performance/browsing_test.rb
  58. +13 −0 episode-273/siteseer-after/test/test_helper.rb
  59. +7 −0 episode-273/siteseer-after/test/unit/location_test.rb
  60. 0 episode-273/siteseer-after/vendor/plugins/.gitkeep
  61. +4 −0 episode-273/siteseer-before/.gitignore
  62. +5 −0 episode-273/siteseer-before/Gemfile
  63. +77 −0 episode-273/siteseer-before/Gemfile.lock
  64. +7 −0 episode-273/siteseer-before/README
  65. +7 −0 episode-273/siteseer-before/Rakefile
  66. +3 −0 episode-273/siteseer-before/app/controllers/application_controller.rb
  67. +2 −0 episode-273/siteseer-before/app/helpers/application_helper.rb
  68. +23 −0 episode-273/siteseer-before/app/helpers/error_messages_helper.rb
  69. +22 −0 episode-273/siteseer-before/app/helpers/layout_helper.rb
  70. +19 −0 episode-273/siteseer-before/app/views/layouts/application.html.erb
  71. +4 −0 episode-273/siteseer-before/config.ru
  72. +42 −0 episode-273/siteseer-before/config/application.rb
  73. +6 −0 episode-273/siteseer-before/config/boot.rb
  74. +22 −0 episode-273/siteseer-before/config/database.yml
  75. +5 −0 episode-273/siteseer-before/config/environment.rb
  76. +26 −0 episode-273/siteseer-before/config/environments/development.rb
  77. +49 −0 episode-273/siteseer-before/config/environments/production.rb
  78. +35 −0 episode-273/siteseer-before/config/environments/test.rb
  79. +7 −0 episode-273/siteseer-before/config/initializers/backtrace_silencers.rb
  80. +10 −0 episode-273/siteseer-before/config/initializers/inflections.rb
  81. +5 −0 episode-273/siteseer-before/config/initializers/mime_types.rb
  82. +7 −0 episode-273/siteseer-before/config/initializers/secret_token.rb
  83. +8 −0 episode-273/siteseer-before/config/initializers/session_store.rb
  84. +5 −0 episode-273/siteseer-before/config/locales/en.yml
  85. +58 −0 episode-273/siteseer-before/config/routes.rb
  86. +7 −0 episode-273/siteseer-before/db/seeds.rb
  87. +2 −0 episode-273/siteseer-before/doc/README_FOR_APP
  88. 0 episode-273/siteseer-before/lib/tasks/.gitkeep
  89. +26 −0 episode-273/siteseer-before/public/404.html
  90. +26 −0 episode-273/siteseer-before/public/422.html
  91. +26 −0 episode-273/siteseer-before/public/500.html
  92. 0 episode-273/siteseer-before/public/favicon.ico
  93. BIN episode-273/siteseer-before/public/images/rails.png
  94. +2 −0 episode-273/siteseer-before/public/javascripts/application.js
  95. +965 −0 episode-273/siteseer-before/public/javascripts/controls.js
  96. +974 −0 episode-273/siteseer-before/public/javascripts/dragdrop.js
  97. +1,123 −0 episode-273/siteseer-before/public/javascripts/effects.js
  98. +6,001 −0 episode-273/siteseer-before/public/javascripts/prototype.js
  99. +191 −0 episode-273/siteseer-before/public/javascripts/rails.js
  100. +5 −0 episode-273/siteseer-before/public/robots.txt
  101. 0 episode-273/siteseer-before/public/stylesheets/.gitkeep
  102. +75 −0 episode-273/siteseer-before/public/stylesheets/application.css
  103. +6 −0 episode-273/siteseer-before/script/rails
  104. +9 −0 episode-273/siteseer-before/test/performance/browsing_test.rb
  105. +13 −0 episode-273/siteseer-before/test/test_helper.rb
  106. 0 episode-273/siteseer-before/vendor/plugins/.gitkeep
View
@@ -0,0 +1,8 @@
+RailsCasts Episode #273: Geocoder
+
+http://railscasts.com/episodes/273-geocoder
+
+Commands used in episode
+
+ rails g nifty:scaffold location address:string latitude:float longitude:float
+ bundle
@@ -0,0 +1,4 @@
+.bundle
+db/*.sqlite3
+log/*.log
+tmp/
@@ -0,0 +1,7 @@
+source 'http://rubygems.org'
+
+gem 'rails', '3.0.9'
+gem 'sqlite3'
+gem 'nifty-generators'
+
+gem 'geocoder'
@@ -0,0 +1,79 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ actionmailer (3.0.9)
+ actionpack (= 3.0.9)
+ mail (~> 2.2.19)
+ actionpack (3.0.9)
+ activemodel (= 3.0.9)
+ activesupport (= 3.0.9)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.5.0)
+ rack (~> 1.2.1)
+ rack-mount (~> 0.6.14)
+ rack-test (~> 0.5.7)
+ tzinfo (~> 0.3.23)
+ activemodel (3.0.9)
+ activesupport (= 3.0.9)
+ builder (~> 2.1.2)
+ i18n (~> 0.5.0)
+ activerecord (3.0.9)
+ activemodel (= 3.0.9)
+ activesupport (= 3.0.9)
+ arel (~> 2.0.10)
+ tzinfo (~> 0.3.23)
+ activeresource (3.0.9)
+ activemodel (= 3.0.9)
+ activesupport (= 3.0.9)
+ activesupport (3.0.9)
+ arel (2.0.10)
+ builder (2.1.2)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ geocoder (1.0.2)
+ i18n (0.5.0)
+ mail (2.2.19)
+ activesupport (>= 2.3.6)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.16)
+ nifty-generators (0.4.6)
+ polyglot (0.3.1)
+ rack (1.2.3)
+ rack-mount (0.6.14)
+ rack (>= 1.0.0)
+ rack-test (0.5.7)
+ rack (>= 1.0)
+ rails (3.0.9)
+ actionmailer (= 3.0.9)
+ actionpack (= 3.0.9)
+ activerecord (= 3.0.9)
+ activeresource (= 3.0.9)
+ activesupport (= 3.0.9)
+ bundler (~> 1.0)
+ railties (= 3.0.9)
+ railties (3.0.9)
+ actionpack (= 3.0.9)
+ activesupport (= 3.0.9)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (~> 0.14.4)
+ rake (0.9.2)
+ rdoc (3.8)
+ sqlite3 (1.3.3)
+ thor (0.14.6)
+ treetop (1.4.9)
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.29)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ geocoder
+ nifty-generators
+ rails (= 3.0.9)
+ sqlite3
@@ -0,0 +1,7 @@
+= RailsCasts Example Application
+
+Run these commands to try it out.
+
+ bundle
+ rake db:migrate
+ rails s
@@ -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'
+
+Siteseer::Application.load_tasks
@@ -0,0 +1,3 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+end
@@ -0,0 +1,45 @@
+class LocationsController < ApplicationController
+ def index
+ if params[:search].present?
+ @locations = Location.near(params[:search], 50, :order => :distance)
+ else
+ @locations = Location.all
+ end
+ end
+
+ def show
+ @location = Location.find(params[:id])
+ end
+
+ def new
+ @location = Location.new
+ end
+
+ def create
+ @location = Location.new(params[:location])
+ if @location.save
+ redirect_to @location, :notice => "Successfully created location."
+ else
+ render :action => 'new'
+ end
+ end
+
+ def edit
+ @location = Location.find(params[:id])
+ end
+
+ def update
+ @location = Location.find(params[:id])
+ if @location.update_attributes(params[:location])
+ redirect_to @location, :notice => "Successfully updated location."
+ else
+ render :action => 'edit'
+ end
+ end
+
+ def destroy
+ @location = Location.find(params[:id])
+ @location.destroy
+ redirect_to locations_url, :notice => "Successfully destroyed location."
+ 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] ||= I18n.t(:"activerecord.errors.header", :default => "Invalid Fields")
+ options[:message] ||= I18n.t(:"activerecord.errors.message", :default => "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) { 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 LocationsHelper
+end
@@ -0,0 +1,5 @@
+class Location < ActiveRecord::Base
+ attr_accessible :address, :latitude, :longitude
+ geocoded_by :address
+ after_validation :geocode, :if => :address_changed?
+end
@@ -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>
@@ -0,0 +1,16 @@
+<%= form_for @location do |f| %>
+ <%= f.error_messages %>
+ <p>
+ <%= f.label :address %><br />
+ <%= f.text_field :address %>
+ </p>
+ <p>
+ <%= f.label :latitude %><br />
+ <%= f.text_field :latitude %>
+ </p>
+ <p>
+ <%= f.label :longitude %><br />
+ <%= f.text_field :longitude %>
+ </p>
+ <p><%= f.submit %></p>
+<% end %>
@@ -0,0 +1,8 @@
+<% title "Edit Location" %>
+
+<%= render 'form' %>
+
+<p>
+ <%= link_to "Show", @location %> |
+ <%= link_to "View All", locations_path %>
+</p>
@@ -0,0 +1,28 @@
+<% title "Locations" %>
+
+<%= form_tag locations_path, :method => :get do %>
+ <p>
+ <%= text_field_tag :search, params[:search] %>
+ <%= submit_tag "Search Near", :name => nil %>
+ </p>
+<% end %>
+
+<table>
+ <tr>
+ <th>Address</th>
+ <th>Latitude</th>
+ <th>Longitude</th>
+ </tr>
+ <% for location in @locations %>
+ <tr>
+ <td><%= location.address %></td>
+ <td><%= location.latitude %></td>
+ <td><%= location.longitude %></td>
+ <td><%= link_to "Show", location %></td>
+ <td><%= link_to "Edit", edit_location_path(location) %></td>
+ <td><%= link_to "Destroy", location, :confirm => 'Are you sure?', :method => :delete %></td>
+ </tr>
+ <% end %>
+</table>
+
+<p><%= link_to "New Location", new_location_path %></p>
@@ -0,0 +1,5 @@
+<% title "New Location" %>
+
+<%= render 'form' %>
+
+<p><%= link_to "Back to List", locations_path %></p>
@@ -0,0 +1,29 @@
+<% title "Location" %>
+
+<p>
+ <strong>Address:</strong>
+ <%= @location.address %>
+</p>
+<p>
+ <strong>Latitude:</strong>
+ <%= @location.latitude %>
+</p>
+<p>
+ <strong>Longitude:</strong>
+ <%= @location.longitude %>
+</p>
+
+<%= image_tag "http://maps.google.com/maps/api/staticmap?size=450x300&sensor=false&zoom=16&markers=#{@location.latitude}%2C#{@location.longitude}" %>
+
+<h3>Nearby locations</h3>
+<ul>
+<% for location in @location.nearbys(10) %>
+ <li><%= link_to location.address, location %> (<%= location.distance.round(2) %> miles)</li>
+<% end %>
+</ul>
+
+<p>
+ <%= link_to "Edit", edit_location_path(@location) %> |
+ <%= link_to "Destroy", @location, :confirm => 'Are you sure?', :method => :delete %> |
+ <%= link_to "View All", locations_path %>
+</p>
@@ -0,0 +1,4 @@
+# This file is used by Rack-based servers to start the application.
+
+require ::File.expand_path('../config/environment', __FILE__)
+run Siteseer::Application
@@ -0,0 +1,42 @@
+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 Siteseer
+ 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.
+
+ # 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
+
+ # JavaScript files you want as :defaults (application.js is always included).
+ # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
+
+ # 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]
+ 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'])
Oops, something went wrong. Retry.

0 comments on commit 66b49e6

Please sign in to comment.