1

I have a set of commands that I run in the bin/rails console, for example:

AppConfig.settings.captcha.enable = false
success = user.sign_up
etc ...

Can I make a script like bin/bash to execute all commands at once? (I would like it to be a executable file, since I want to change the input data in it)

0

1 Answer 1

1

You can put the commands into a file (script), add the shebang line (#!/usr/bin/env ruby), make the file executable and run it from the command line like so:

#!/usr/bin/env ruby
# require ... (load the libraries here)
...
AppConfig.settings.captcha.enable = false
success = user.sign_up
#etc ...
# Make executable
chmod u+x my_script.rb

# Run the script
/path/to/my_script.rb
Sign up to request clarification or add additional context in comments.

4 Comments

If I need to enter: "bin/rails console development" to start the shell, then enter this path in "require"?
No, just require the libraries you are using (for example, require pg, require active_record, etc). The command you mention, bin/rails console, lets you interact with your Rails application from the command line. It is not a library that you need to load in your ruby script.
What does the code look like if I first need to go to "bin / rails console"?
Sorry, perhaps I misunderstood your question. I thought you already had your code (which you posted) that you ran successfully in bin/rails console . If that's incorrect, I did not answer your question. It may be worth posting this as another, different, question, perhaps with some additional clarification.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.