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.

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.


You can put your Ruby file into the /lib folder and execute it through:

rails r lib/script.rb

That's it.


Need Your Help

NSMutableArray memory leak when reloading objects

ios memory-leaks three20 ttthumbsviewcontroller

I am using Three20/TTThumbsviewcontroller to load photos. I am struggling since quite a some time now to fix memory leak in setting photosource. I am beginner in Object C & iOS memory management.

Longest common substring

python algorithm

I am trying to create a program which will receive two strings and compeer between, and returns the largest common letters in the order they appear.