Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Runner in Ruby on Rails

What is script/runner?

What is a runner?

How do I use runner on a Ruby file?

What are all the commands typed out on the command prompt?

I'm using Windows by the way.

like image 632
Ravikiran Avatar asked Jun 14 '12 16:06

Ravikiran


People also ask

How do I run a rail in terminal?

Go to your browser and open http://localhost:3000, you will see a basic Rails app running. You can also use the alias "s" to start the server: bin/rails s . The server can be run on a different port using the -p option. The default development environment can be changed using -e .

How do I create a controller in Rails?

To generate a controller and optionally its actions, do the following: Press Ctrl twice and start typing rails g controller. Select rails g controller and press Enter . In the invoked Add New Controller dialog, specify the controller name.

What is a Rails script?

The Rails include code generation scripts, which are used to automatically generate model and controller classes for an application. Code generation increases your productivity when developing Web applications. By running generator command, skeleton files for all your model and controller classes will be generated.


1 Answers

From the Rails Guides:

1.7 rails runner

runner runs Ruby code in the context of Rails non-interactively. For instance:

$ rails runner "Model.long_running_method" 

You can also use the alias “r” to invoke the runner: rails r.

You can specify the environment in which the runner command should operate using the -e switch.

$ rails runner -e staging "Model.long_running_method" 

Any code to be run must be loaded as a part of your Rails app, i.e. either in app/ or lib/, among other places.

like image 186
Andrew Marshall Avatar answered Oct 14 '22 12:10

Andrew Marshall