The Depot Application

The Depot Application

17 Migration 15 Rails In Depth

16 Active Support

ruby -rubygems /home/rubys/git/rails/bin/rails new namelist
      create  
      create  README
      create  Rakefile
      create  config.ru
      create  .gitignore
      create  Gemfile
      create  app
      create  app/helpers/application_helper.rb
      create  app/views/layouts/application.html.erb
      create  app/controllers/application_controller.rb
      create  app/mailers
      create  app/models
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.rb
      create  config/environments
      create  config/environments/development.rb
      create  config/environments/test.rb
      create  config/environments/production.rb
      create  config/initializers
      create  config/initializers/mime_types.rb
      create  config/initializers/inflections.rb
      create  config/initializers/session_store.rb
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/secret_token.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/500.html
      create  public/robots.txt
      create  public/favicon.ico
      create  public/422.html
      create  public/404.html
      create  public/index.html
      create  public/images
      create  public/images/rails.png
      create  public/stylesheets
      create  public/stylesheets/.gitkeep
      create  public/javascripts
      create  public/javascripts/prototype.js
      create  public/javascripts/dragdrop.js
      create  public/javascripts/rails.js
      create  public/javascripts/effects.js
      create  public/javascripts/controls.js
      create  public/javascripts/application.js
      create  script
      create  script/rails
      create  test
      create  test/performance/browsing_test.rb
      create  test/test_helper.rb
      create  test/fixtures
      create  test/unit
      create  test/functional
      create  test/integration
      create  tmp
      create  tmp/sessions
      create  tmp/sockets
      create  tmp/cache
      create  tmp/pids
      create  vendor/plugins
      create  vendor/plugins/.gitkeep
bundle install
Using rake (0.8.7) 
Using abstract (1.0.0) 
Using activesupport (3.0.1.pre) from source at /home/rubys/git/rails 
Using builder (2.1.2) 
Using i18n (0.4.1) 
Using activemodel (3.0.1.pre) from source at /home/rubys/git/rails 
Using erubis (2.6.6) 
Using rack (1.2.1) 
Using rack-mount (0.6.13) 
Using rack-test (0.5.4) 
Using tzinfo (0.3.23) 
Using actionpack (3.0.1.pre) from source at /home/rubys/git/rails 
Using mime-types (1.16) 
Using polyglot (0.3.1) 
Using treetop (1.4.8) 
Using mail (2.2.5) 
Using actionmailer (3.0.1.pre) from source at /home/rubys/git/rails 
Using arel (1.0.1) from source at /home/rubys/git/arel 
Using activerecord (3.0.1.pre) from source at /home/rubys/git/rails 
Using activeresource (3.0.1.pre) from source at /home/rubys/git/rails 
Using bundler (1.0.0) 
Using thor (0.14.0) 
Using railties (3.0.1.pre) from source at /home/rubys/git/rails 
Using rails (3.0.1.pre) from source at /home/rubys/git/rails 
Using sqlite3-ruby (1.3.1) 
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
*[32m
Your bundle was installed to `/home/rubys/.rvm/gems/ruby-1.8.7-p302`*[0m
edit config/routes.rb
Namelist::Application.routes.draw do
  # ...
 
  # 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
      invoke  active_record
      create    db/migrate/20100906011411_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 20100906011411_create_people.rb 20100301000001_create_people.rb
(in /home/rubys/git/awdwr/work/namelist)
==  CreatePeople: migrating ===================================================
-- create_table(:people)
   -> 0.0015s
==  CreatePeople: migrated (0.0016s) ==========================================
 
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/namelist/app/views/people/index.html.erb where line #9 raised:

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

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/namelist

Application Trace | Framework Trace | Full Trace
app/views/people/index.html.erb:9:in `_app_views_people_index_html_erb___249175777__620494758_0'
app/views/people/index.html.erb:5:in `each'
app/views/people/index.html.erb:5:in `_app_views_people_index_html_erb___249175777__620494758_0'

Request

Parameters:

{"person"=>{"name"=>"Dave"},
 "utf8"=>"✓",
 "authenticity_token"=>"8OevZbW70cdZTKoV6sK+6fn7qjIkS0jjjDzXceRuEUA="}

Show session dump

Show env dump

Response

Headers:

None

get /people

NoMethodError in People#index

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

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

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/namelist

Application Trace | Framework Trace | Full Trace
app/views/people/index.html.erb:9:in `_app_views_people_index_html_erb___249175777__620860058_0'
app/views/people/index.html.erb:5:in `each'
app/views/people/index.html.erb:5:in `_app_views_people_index_html_erb___249175777__620860058_0'

Request

Parameters:

None

Show session dump

Show env dump

Response

Headers:

None

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

17 Migration 15 Rails In Depth