views:

25

answers:

2

I am reading "Pragmatic Agile Web Development with Rails (2th ed)" and trying examples from this book. But when I am trying one of examples I have got error.

So:

  • I have created a model for a product

    ruby script/generate model product
    

    Filled the fields:

    class CreateProducts < ActiveRecord::Migration
     def self.up
       create_table :products do |t|
         t.column :title, :string
         t.column :description, :text
         t.column :image_url, :string
       end
     end
    
    
     def self.down
      drop_table :products
     end
    end
    

    Generated the DB:

    rake db:migrate
    
  • Next I have creaded the view:

    ruby script/generate controller admin
    

    Added line to the view:

    class AdminController < ApplicationController
      scaffold :product
    end
    

I have googled and found this solution:

ruby script/generate scaffold product title:string description:text image_url:string

But I am not sure that it is a right way. What is the 'true way' to create a view for the product table ?

+1  A: 

scaffold method has been removed from Rails since about 2.0 version. Since that time, one should use the generator for scaffolding.

neutrino
+1  A: 

To create an example you'd just run

ruby script/generate scaffold Product title:string description:text image_url:string

This will generate MVC structure for products

fantactuka
commas are not needed here. see the author's working solution.
neutrino
Updated, thanks
fantactuka