get a resource

Create the application.

bundle exec /home/rubys/git/rails/railties/bin/rails new depot --skip-bundle --dev
      create  
      create  README.rdoc
      create  Rakefile
      create  config.ru
      create  .gitignore
      create  Gemfile
      create  app
      create  app/assets/images/rails.png
      create  app/assets/javascripts/application.js
      create  app/assets/stylesheets/application.css
      create  app/controllers/application_controller.rb
      create  app/helpers/application_helper.rb
      create  app/mailers
      create  app/models
      create  app/views/layouts/application.html.erb
      create  app/mailers/.keep
      create  app/models/.keep
      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/production.rb
      create  config/environments/test.rb
      create  config/initializers
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/inflections.rb
      create  config/initializers/locale.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/secret_token.rb
      create  config/initializers/session_store.rb
      create  config/initializers/wrap_parameters.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/.keep
      create  lib/assets
      create  lib/assets/.keep
      create  log
      create  log/.keep
      create  public
      create  public/404.html
      create  public/422.html
      create  public/500.html
      create  public/favicon.ico
      create  public/index.html
      create  public/robots.txt
      create  script
      create  script/rails
      create  test/fixtures
      create  test/fixtures/.keep
      create  test/controllers
      create  test/controllers/.keep
      create  test/mailers
      create  test/mailers/.keep
      create  test/models
      create  test/models/.keep
      create  test/helpers
      create  test/helpers/.keep
      create  test/integration
      create  test/integration/.keep
      create  test/performance/browsing_test.rb
      create  test/test_helper.rb
      create  tmp/cache
      create  tmp/cache/assets
      create  vendor/assets/javascripts
      create  vendor/assets/javascripts/.keep
      create  vendor/assets/stylesheets
      create  vendor/assets/stylesheets/.keep
bundle install
Using rake (0.9.2.2) 
Using i18n (0.6.1) 
Using minitest (4.1.0) 
Using multi_json (1.3.6) 
Using tzinfo (0.3.33) 
Using activesupport (4.0.0.beta) 
Using builder (3.1.3) 
Using erubis (2.7.0) 
Using journey (2.0.0.20120723141804) 
Using rack (1.4.1) 
Using rack-test (0.6.2) 
Using actionpack (4.0.0.beta) 
Using mime-types (1.19) 
Using polyglot (0.3.3) 
Using treetop (1.4.11) 
Using mail (2.4.4) 
Using actionmailer (4.0.0.beta) 
Using activemodel (4.0.0.beta) 
Using activerecord-deprecated_finders (0.0.1) 
Using arel (3.0.2.20120819075748) 
Using activerecord (4.0.0.beta) 
Using activeresource (4.0.0.beta) 
Using bcrypt-ruby (3.0.1) 
Using bundler (1.2.0) 
Using highline (1.6.15) 
Using jruby-pageant (1.1.1) 
Using net-ssh (2.6.0) 
Using net-scp (1.0.4) 
Using net-sftp (2.0.5) 
Using net-ssh-gateway (1.1.0) 
Using capistrano (2.13.4) 
Using coffee-script-source (1.3.3) 
Using execjs (1.4.0) 
Using coffee-script (2.2.0) 
Using json (1.7.5) 
Using rdoc (3.12) 
Using thor (0.16.0) 
Using railties (4.0.0.beta) 
Using coffee-rails (4.0.0.beta) 
Using haml (3.1.7) 
Using hike (1.2.1) 
Using htmlentities (4.3.1) 
Using jquery-rails (2.1.3) 
Using kaminari (0.14.1) 
Using mysql2 (0.3.11) 
Using tilt (1.3.3) 
Using sprockets (2.7.0) 
Using sprockets-rails (1.0.1) 
Using rails (4.0.0.beta) 
Using sass (3.2.1) 
Using sass-rails (4.0.0.beta) 
Using sqlite3 (1.3.6) 
Using test-unit (2.5.2) 
Using turbolinks (0.5.1) 
Using uglifier (1.3.0) 
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

Generate our first model and associated scaffolding

rails generate scaffold Product title:string
      invoke  active_record
      create    db/migrate/20121011150055_create_products.rb
      create    app/models/product.rb
      invoke    test_unit
      create      test/models/product_test.rb
      create      test/fixtures/products.yml
      invoke  resource_route
       route    resources :products
      invoke  scaffold_controller
      create    app/controllers/products_controller.rb
      invoke    erb
      create      app/views/products
      create      app/views/products/index.html.erb
      create      app/views/products/edit.html.erb
      create      app/views/products/show.html.erb
      create      app/views/products/new.html.erb
      create      app/views/products/_form.html.erb
      invoke    test_unit
      create      test/controllers/products_controller_test.rb
      invoke    helper
      create      app/helpers/products_helper.rb
      invoke      test_unit
      create        test/helpers/products_helper_test.rb
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/products.js.coffee
      invoke    scss
      create      app/assets/stylesheets/products.css.scss
      invoke  scss
      create    app/assets/stylesheets/scaffolds.css.scss

Apply the migration

rake db:migrate
mv 20121011150055_create_products.rb 20110711000001_create_products.rb
==  CreateProducts: migrating =================================================
-- create_table(:products)
   -> 0.0015s
==  CreateProducts: migrated (0.0016s) ========================================
 

Start the server.

Create a product

get /products/new

New product


Back
post /products
  • product[title] => CoffeeScript
You are being redirected.
get http://localhost:3000/products/1

Product was successfully created.

Title: CoffeeScript

Edit | Back

Show that edit works

get /products/1/edit

Editing product


Show | Back

Define an identical "modify" action

edit app/controllers/products_controller.rb
    def modify
      @product = Product.find(params[:id])
    end

Add to modify to the routes

edit config/routes.rb
    resources :products do
      get :modify, on: :member
    end

Copy the view

cp app/views/products/edit.html.erb app/views/products/modify.html.erb

Show that modify doesn't work

get /products/1/modify

ArgumentError in Products#modify

Showing /var/www/rtest/work/depot/app/views/products/_form.html.erb where line #1 raised:

First argument in form cannot contain nil or be empty

Extracted source (around line #1):

1: <%= form_for(@product) do |f| %>
2:   <% if @product.errors.any? %>
3:     <div id="error_explanation">
4:       <h2><%= pluralize(@product.errors.count, "error") %> prohibited this product from being saved:</h2>

Trace of template inclusion: app/views/products/modify.html.erb

Rails.root: /var/www/rtest/work/depot

Application Trace | Framework Trace | Full Trace
app/views/products/_form.html.erb:1:in `_app_views_products__form_html_erb__341946480165708201_35710020'
app/views/products/modify.html.erb:3:in `_app_views_products_modify_html_erb___1264177198122367652_31476700'

Request

Parameters:

{"id"=>"1"}

Show session dump

Show env dump

Response

Headers:

None

Expected at least 1 element matching "#product_title[value='CoffeeScript']", found 0.
<0> expected to be
>=
<1>.

Traceback:
  resourceGet.rb:53:in `block (2 levels) in <class:ResourceGetTest>'
  /home/rubys/git/gorp/lib/gorp/test.rb:158:in `call'
  /home/rubys/git/gorp/lib/gorp/test.rb:158:in `block (2 levels) in <class:TestCase>'
  resourceGet.rb:52:in `block in <class:ResourceGetTest>'

Environment

Thu, 11 Oct 2012 15:01:03 GMT
echo $PATH
/home/rubys/.rvm/gems/ruby-1.9.3-p194/bin:/home/rubys/.rvm/gems/ruby-1.9.3-p194@global/bin:/home/rubys/.rvm/rubies/ruby-1.9.3-p194/bin:/home/rubys/.rvm/bin:/home/rubys/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
node -v
v0.6.12
/home/rubys/.rvm/rubies/ruby-1.9.3-p194/bin/ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
gem -v
1.8.24
bundle show
Gems included by the bundle:
  * actionmailer (4.0.0.beta)
  * actionpack (4.0.0.beta)
  * activemodel (4.0.0.beta)
  * activerecord (4.0.0.beta)
  * activerecord-deprecated_finders (0.0.1 fe150f2)
  * activeresource (4.0.0.beta 6639bb4)
  * activesupport (4.0.0.beta)
  * arel (3.0.2.20120819075748 de7e7c8)
  * bcrypt-ruby (3.0.1)
  * builder (3.1.3)
  * bundler (1.2.0)
  * capistrano (2.13.4)
  * coffee-rails (4.0.0.beta 82da9a9)
  * coffee-script (2.2.0)
  * coffee-script-source (1.3.3)
  * erubis (2.7.0)
  * execjs (1.4.0)
  * haml (3.1.7)
  * highline (1.6.15)
  * hike (1.2.1)
  * htmlentities (4.3.1)
  * i18n (0.6.1)
  * journey (2.0.0.20120723141804 850267e)
  * jquery-rails (2.1.3)
  * jruby-pageant (1.1.1)
  * json (1.7.5)
  * kaminari (0.14.1)
  * mail (2.4.4)
  * mime-types (1.19)
  * minitest (4.1.0)
  * multi_json (1.3.6)
  * mysql2 (0.3.11)
  * net-scp (1.0.4)
  * net-sftp (2.0.5)
  * net-ssh (2.6.0)
  * net-ssh-gateway (1.1.0)
  * polyglot (0.3.3)
  * rack (1.4.1)
  * rack-test (0.6.2)
  * rails (4.0.0.beta cd98c25)
  * railties (4.0.0.beta)
  * rake (0.9.2.2)
  * rdoc (3.12)
  * sass (3.2.1)
  * sass-rails (4.0.0.beta 9b60259)
  * sprockets (2.7.0)
  * sprockets-rails (1.0.1 e7146b7)
  * sqlite3 (1.3.6)
  * test-unit (2.5.2)
  * thor (0.16.0)
  * tilt (1.3.3)
  * treetop (1.4.11)
  * turbolinks (0.5.1)
  * tzinfo (0.3.33)
  * uglifier (1.3.0)
rake about
About your application's environment
Ruby version              1.9.3 (x86_64-linux)
RubyGems version          1.8.24
Rack version              1.4
Rails version             4.0.0.beta
JavaScript Runtime        Node.js (V8)
Active Record version     4.0.0.beta
Action Pack version       4.0.0.beta
Action Mailer version     4.0.0.beta
Active Support version    4.0.0.beta
Middleware                ActionDispatch::Static, Rack::Lock, #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x00000002568a68>, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::DebugExceptions, ActionDispatch::RemoteIp, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::Migration::CheckPending, ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::Head, Rack::ConditionalGet, Rack::ETag, ActionDispatch::BestStandardsSupport
Application root          /var/www/rtest/work/depot
Environment               development
Database adapter          sqlite3
Database schema version   20110711000001
git log -1
commit cd98c25ebedc27fe892468bb87ea260fb070f5eb
Merge: e5e174a a1d2f69
Author: Vijay Dev <vijaydev.cse@gmail.com>
Date:   Wed Oct 10 22:43:42 2012 -0700
    Merge pull request #7050 from kytrinyx/documentation-reset-column-info
    
    Expand the caveat about models in migrations in the rails guide.