如何快速新建一個Ruby on Rails 項目

此文根據(jù)如下鏈接撰寫
https://launchschool.com/blog/integrating-rails-and-bootstrap-part-1

首先必須安裝Ruby on Rails。

新建一個叫做**myforum**的Rails app(以下所有命令在iTerm中輸入):

rails new myforum

生成 MyForum 的model

rails generate scaffold MyForm title:string descrption:text

把變更移到database

rake db:migrate

編寫seeds.rb文件,批量寫入數(shù)據(jù)

打開db/seeds.rb文件,寫入:

# db/seeds.rb

MyForum.create!(title: 'grocery shopping', descrption: 'pickles, eggs, red onion')
MyForum.create!(title: 'wash the car')
MyForum.create!(title: 'register kids for school', descrption: 'Register Kira for Ruby Junior High and Caleb for Rails High School')
Todo.create!(title: 'check engine light', descrption: 'The check engine light is on in the Tacoma')
Todo.create!(title: 'dog groomers', descrption: 'Take Pinky and Redford to the groomers on Wednesday the 23rd')

在ITerm里執(zhí)行命令

rake db:seed

設置主頁路徑

在 config/routes.rb 文件里, 加入 root 'myforums#index'

最后,在server上預覽,在iTerm中輸入:

rails s
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容