Post

The Rails Runner

Using the Rails Runner to run Ruby scripts within the Rails environment for testing, data fixes, or accessing models directly.

The Rails Runner lets you run Ruby code in the context of your Rails application without starting the full server. It’s useful for testing scripts, accessing models, or quickly manipulating data.

Creating a simple file for testing in which we have access to rails methods, the database and other useful stuff.

1
2
user = User.first
puts "First user: #{user.name}"
1
rails runner test.rb
This post is licensed under CC BY-NC 4.0 by the author.