CSS

Rails常用命令筆記

rails generate 命令生成的文件

命令 概要 controller view help model migration
scaffold  全部生成  v  v  v  v  v
 controller  生成controller和view  v  v  v
 model  model  v  v
 migrate  生成migration文件  v

rails g controller

$ rails g controller NAME [action action] [options]

rails g controller CreditCards open debit credit close

 

rails g model

rails g model NAME [field[:type][:index] field[:type][:index]] [options]

rails g post title:string body:text published:boolean

 

rails g migration

透過此方式寫ruby代碼即可修改數據庫,ex創建表和添加column ….等等

rails g model NAME [field[:type][:index] field[:type][:index]] [options]

rails g migration add_image_url_to_post image_url:string

向posts表中添加類型為string的column


創建新的項目

rails new NAME

rails new appname

會自動生成單元測試,若不生成測試的命令是

rails new app –skip-test-unit

 

啟動Server

rails s

 

指定啟動環境

rails server -e

默認是 development環境,若要使用測試環境啟動server指令則為

rails server -etest   或   rails server –environment=test

 

指定啟動端口

rails server -p

默認是3000

rails server -p4000  或 rails server –port=4000


 

rails console

rails c -s

操作完後會回退,不會影響數據內容

 

rails c -e

指定啟動環境,與rails server類似

© 2024 胡同筆記 | WordPress Theme: Cosimo by CrestaProject.