close

依照"rails敏捷開發網站"做練習

結果發現錯誤

原來版本rails 2.0做了很大更動

試了好多次錯誤終於試出來 (很多人說載什麼東西之類的 但雞仔始終還是錯...)

後來才發現rails2.0的scaffold的新用法 (很多人說rails 2.0將scaffold改成plug-in)

所以還是先安裝好了 XD

ruby script/plugin install scaffolding

不知道移除後有沒有差

今天光研究這就研究很久

下次再試試

 


 

step1: rails depot (建立rails專案)

step2:  script/generate scaffold product title:string description:text image_url:string  (新的scaffold用法)
             產生一個product的model
             string型別title欄位 text型別description欄位 string型別image_url欄位 共3個欄位
             一個products的controller & 對應的view
             在config/route.rb中加入 "map.resource :products" 代表將products model視為一個resource

step3: 建好後更改 config/database.yml (配置自己的資料庫)


development:
  adapter: mysql
  database: depot_development
  username: root
  password:
  host: localhost

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: mysql
  database: depot_development
  username: root
  password:
  host: localhost

production:
  adapter: mysql
  database: depot_development
  username: root
  password:
  host: localhost

step4: rake db:create

step5: 修改遷移檔 /db/migrate 使應用程式去map

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

      t.timestamps
    end
  end

  def self.down
    drop_table :products
  end
end

step6:  rake db:migrate 執行神奇指令

step7: http://localhost:3000/products

1.jpg

點下new product

2.jpg

終於出現跟書上一樣的範例了

想知道rails 2.0 "REST"概念的

可以參考此部落格 http://devpoga.wordpress.com/

也是因為此神人的blog讓雞仔解決了問題阿 (感謝~)

 

 

arrow
arrow
    全站熱搜

    flyinsky76 發表在 痞客邦 留言(0) 人氣()