4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

rails コマンド 覚書

Last updated at Posted at 2018-04-17

基本のコマンド

プロジェクト作成

$ rails new app_name

サーバー起動

# どちらでも使える
$ rails server
$ rails s

コントローラー・モデル作成

# どちらでも使える
$ rails generate controller controller_name action_name
$ rails g model model_name column_name:type

rails console

モデル作成+保存 new + save

> Post.create(title: "hoge", content: "hogehoge")

テーブル一覧確認
出典 https://qiita.com/littlekbt/items/4847a6b73050bfc4a46e

> ActiveRecord::Base.connection.tables

レコードの有無確認
出典 http://o.inchiki.jp/obbr/146

> Post.exists?
#ある
=> true
#ない
=> false

終了する

# どちらでも使える
> quit
> exit

rails dbconsole

テーブル一覧確認

sqlite> .table
users            posts

テーブルの中身確認

sqlite> select * from <テーブル名>;

終了する

# どちらでも使える
sqlite> .quit
sqlite> .exit
4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?