Reputation: 45335
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
Have runned the server and have got error:
undefined method `scaffold' for AdminController:Class
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 ?
Upvotes: 0
Views: 960
Reputation: 3334
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
Upvotes: 1
Reputation: 24174
scaffold
method has been removed from Rails since about 2.0 version. Since that time, one should use the generator for scaffolding.
Upvotes: 2