The Depot Application

The Depot Application

16 Active Support 15 Rails In Depth

16 Active Support

ruby -rubygems /home/rubys/git/rails/railties/bin/rails namelist
      create  
      create  README
      create  .gitignore
      create  Rakefile
      create  config.ru
      create  Gemfile
      create  app
      create  app/helpers/application_helper.rb
      create  app/controllers/application_controller.rb
      create  app/views/layouts
      create  app/models
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.rb
      create  config/environments
      create  config/environments/test.rb
      create  config/environments/production.rb
      create  config/environments/development.rb
      create  config/initializers
      create  config/initializers/session_store.rb
      create  config/initializers/inflections.rb
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/cookie_verification_secret.rb
      create  config/initializers/mime_types.rb
      create  config/locales
      create  config/locales/en.yml
      create  config/boot.rb
      create  config/database.yml
      create  db
      create  db/seeds.rb
      create  doc
      create  doc/README_FOR_APP
      create  lib
      create  lib/tasks
      create  lib/tasks/.gitkeep
      create  log
      create  log/server.log
      create  log/production.log
      create  log/development.log
      create  log/test.log
      create  public
      create  public/404.html
      create  public/500.html
      create  public/index.html
      create  public/robots.txt
      create  public/422.html
      create  public/favicon.ico
      create  public/images
      create  public/images/rails.png
      create  public/stylesheets
      create  public/stylesheets/.gitkeep
      create  public/javascripts
      create  public/javascripts/rails.js
      create  public/javascripts/controls.js
      create  public/javascripts/application.js
      create  public/javascripts/dragdrop.js
      create  public/javascripts/prototype.js
      create  public/javascripts/effects.js
      create  script
      create  script/rails
      create  test
      create  test/performance/browsing_test.rb
      create  test/test_helper.rb
      create  test/integration
      create  test/unit
      create  test/functional
      create  test/fixtures
      create  tmp
      create  tmp/sessions
      create  tmp/sockets
      create  tmp/cache
      create  tmp/pids
      create  vendor/plugins
      create  vendor/plugins/.gitkeep
bundle install
Resolving dependencies
Installing abstract (1.0.0) from system gems 
Installing actionmailer (3.0.0.beta1) from source code at /home/rubys/git/rails 
Installing actionpack (3.0.0.beta1) from source code at /home/rubys/git/rails 
Installing activemodel (3.0.0.beta1) from source code at /home/rubys/git/rails 
Installing activerecord (3.0.0.beta1) from source code at /home/rubys/git/rails 
Installing activeresource (3.0.0.beta1) from source code at /home/rubys/git/rails 
Installing activesupport (3.0.0.beta1) from source code at /home/rubys/git/rails 
Installing arel (0.2.1) from system gems 
Installing builder (2.1.2) from system gems 
Installing bundler (0.9.4) from system gems 
Installing erubis (2.6.5) from system gems 
Installing i18n (0.3.3) from system gems 
Installing mail (2.1.2) from system gems 
Installing memcache-client (1.7.8) from system gems 
Installing mime-types (1.16) from system gems 
Installing rack (1.1.0) from system gems 
Installing rack-mount (0.4.7) from system gems 
Installing rack-test (0.5.3) from system gems 
Installing rails (3.0.0.beta1) from source code at /home/rubys/git/rails 
Installing railties (3.0.0.beta1) from source code at /home/rubys/git/rails 
Installing rake (0.8.7) from system gems 
Installing sqlite3-ruby (1.2.5) from system gems 
Installing text-format (1.0.0) from system gems 
Installing text-hyphen (1.0.0) from system gems 
Installing thor (0.13.0) from system gems 
Installing tzinfo (0.3.16) from system gems 
Your bundle is complete!
edit config/routes.rb
Namelist::Application.routes.draw do |map|
  # ...
 
  # This is a legacy wild controller route that's not recommended for RESTful applications.
  # Note: This route will make all actions in every controller accessible via GET requests.
   match ':controller(/:action(/:id(.:format)))'
end

Restart the server.

rails generate model person name:string
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:14: warning: already initialized constant VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:14: warning: already initialized constant RubyGemsVersion
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:194: warning: already initialized constant MUTEX
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:196: warning: already initialized constant RubyGemsPackageVersion
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:202: warning: already initialized constant WIN_PATTERNS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:1079: warning: already initialized constant MARSHAL_SPEC_DIR
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems.rb:1084: warning: already initialized constant YAML_SPEC_DIR
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/version.rb:72: warning: already initialized constant VERSION_PATTERN
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/requirement.rb:20: warning: already initialized constant OPS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/requirement.rb:30: warning: already initialized constant OP_RE
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/version.rb:246: warning: already initialized constant Requirement
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:18: warning: already initialized constant TYPES
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/platform.rb:171: warning: already initialized constant RUBY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/platform.rb:177: warning: already initialized constant CURRENT
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:39: warning: already initialized constant NONEXISTENT_SPECIFICATION_VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:50: warning: already initialized constant CURRENT_SPECIFICATION_VERSION
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:56: warning: already initialized constant SPECIFICATION_VERSION_HISTORY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:72: warning: already initialized constant MARSHAL_FIELDS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:75: warning: already initialized constant TODAY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/source_index.rb:593: warning: already initialized constant Cache
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:14: warning: already initialized constant DEFAULT_BACKTRACE
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:15: warning: already initialized constant DEFAULT_BENCHMARK
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:16: warning: already initialized constant DEFAULT_BULK_THRESHOLD
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:17: warning: already initialized constant DEFAULT_VERBOSITY
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:18: warning: already initialized constant DEFAULT_UPDATE_SOURCES
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:24: warning: already initialized constant OPERATING_SYSTEM_DEFAULTS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:30: warning: already initialized constant PLATFORM_DEFAULTS
/home/rubys/.rvm/ruby-1.9.1-p376/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:53: warning: already initialized constant SYSTEM_WIDE_CONFIG_FILE
      invoke  active_record
      create    db/migrate/20100211191522_create_people.rb
      create    app/models/person.rb
      invoke    test_unit
      create      test/unit/person_test.rb
      create      test/fixtures/people.yml
rake db:migrate
mv 20100211191522_create_people.rb 20100301000001_create_people.rb
(in /home/rubys/git/awdwr/work-191/namelist)
==  CreatePeople: migrating ===================================================
-- create_table(:people)
   -> 0.0011s
==  CreatePeople: migrated (0.0012s) ==========================================
 
edit app/controllers/people_controller.rb
class PeopleController < ApplicationController
 
  def index
    @person = Person.new(params[:person])
    @person.save! if request.post?
    @people = Person.find(:all)
  end
end
edit app/views/layouts/people.html.erb
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"></meta>
    <title>My Name List</title>
  </head>
  <body>
    <%= yield :layout %>
  </body>
</html>
mkdir app/views/people
edit app/views/people/index.html.erb
<table border="1">
  <tr>
    <th>Name</th><th>bytes</th><th>chars</th><th>reversed</th>
  </tr>
  <% for person in @people %>
    <tr>  
      <td><%=h person.name %></td>
      <td><%= person.name.length %></td>
      <td><%= person.name.chars.length %></td>
      <td><%=h person.name.chars.reverse %></td>
    </tr>
  <% end %>
</table>
 
<% form_for :person do |form| %>
  New name: <%= form.text_field :name %>
  <%= submit_tag "Add" %>
<% end %>
get /people
Namebytescharsreversed
New name:
post /people

NoMethodError in People#index

Showing /home/rubys/git/awdwr/work-191/namelist/app/views/people/index.html.erb where line #9 raised:

undefined method `length' for #<Enumerator:0x00000003ab1f38>

Extracted source (around line #9):

6:     <tr>  
7:       <td><%=h person.name %></td>
8:       <td><%= person.name.length %></td>
9:       <td><%= person.name.chars.length %></td>
10:       <td><%=h person.name.chars.reverse %></td>
11:     </tr>
12:   <% end %>

Rails.root: /home/rubys/git/awdwr/work-191/namelist

Application Trace | Framework Trace | Full Trace

Request

Parameters:

{"person"=>{"name"=>"Dave"},
 "authenticity_token"=>"M/jqMSo+qg1HH4bciuBkEqcRngBYurQkVMW0NmMmrXA="}

Show session dump

Show env dump

Response

Headers:

None

get /people

NoMethodError in People#index

Showing /home/rubys/git/awdwr/work-191/namelist/app/views/people/index.html.erb where line #9 raised:

undefined method `length' for #<Enumerator:0x00000003561a40>

Extracted source (around line #9):

6:     <tr>  
7:       <td><%=h person.name %></td>
8:       <td><%= person.name.length %></td>
9:       <td><%= person.name.chars.length %></td>
10:       <td><%=h person.name.chars.reverse %></td>
11:     </tr>
12:   <% end %>

Rails.root: /home/rubys/git/awdwr/work-191/namelist

Application Trace | Framework Trace | Full Trace

Request

Parameters:

None

Show session dump

Show env dump

Response

Headers:

None

sqlite3> select name,length(name) from people where name like 'G%'