Rails Console Cheat Sheet

< Blog

A quick reference to Rails Console.

Created on: 2019-01-22

Tag: cheat_sheet

Save rails console output to file

To save rails console output to a file, do the following 1:

f = File.new("$file_name", 'w')
f << command
f.close

Show all user

Run the following command to see all user 2:

User.all

Show all user with pretty print

Run the following command to see all user with pretty print 2:

pp User.all

Delete user

To delete a user run the following 2:: user = User.find_by_display_name("My New User Name") user.delete

Source

1

rails - Redirecting console output to a file

2(1,2,3)

Deleting Users with Rails Console