LoginSignup
13
12

More than 5 years have passed since last update.

rails console入門

Posted at

rails consoleとは

irbというrailsを読み込んだ環境でrubyを実行できるツール。全部のモデルを参照することができる。

操作

起動のさせ方

rails c

閉じ方

exit

もしくは

quit

modelの値を確認する

rails cでconsoleの起動

rails c

変数に入れる

@tasks = Task.all

@tasksにTaskのオブジェクトを入れる

値の取り出し

puts @tasks.content

=>@tasksのcontent

テーブルの内容を確認

Tomato.all #すべてのレコードを取得する
Tomato.find(1) #idが1のレコードを取得
Tomato.where('id< ?',3) #idが3より小さいレコードを取得
13
12
1

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
13
12