开发者

Create a view for the model

开发者 https://www.devze.com 2023-01-08 07:39 出处:网络
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.

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
    

    Fille开发者_C百科d 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:

      http://localhost:3000/admin

      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 ?


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号