close

作好了 Blog controller 之後。現在來產生 model。

scrip/generate model [model name]

  

打開 db/migrate 下的 migration 檔案。

一篇 Post 要有哪些欄位呢?(通常是標題和內容)

rake db:migrate

自動幫忙開好資料表以及欄位。

----

為加速 Tutorial 的進行。我預先將 CRUD 的範例程式碼貼出,你可以先依樣畫葫蘆的實做試玩,我會在下一節另行解釋這些 code 的運作原理。

 

app/controllers/blogs_controlle.erb

 

app/views/blogs/new.html.erb

 

app/views/blogs/index.html.erb

 

app/views/blogs/edit.html.erb

 

app/views/blogs/show.html.erb


最後,在 routes.rb 加入

arrow
arrow
    全站熱搜

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