1

I need to be able to generate a model (and later a migration) by executing a Linux shell script.

The script is located directly in the app folder and looks like this:

#!/bin/bash

cd /home/<my_user_profile>/Websites/<my_app_name>
rails g model my_model name:string accepted:boolean [etc...]

The problem is: When I execute the script, the model does not get created. Any ideas why?

6
  • Any reason you're not using a Rails generator? Commented Oct 27, 2011 at 20:32
  • @coreyward: Thanks a lot for the suggestion, I definitely will check that out (but still curious about my issue...). Commented Oct 27, 2011 at 20:51
  • @Dave Newton: Nothing happens, the console gets ready for another command, as if the first command was executed successfully... Commented Oct 27, 2011 at 20:52
  • @TomDogg Are you using rvm or anything? W/o the shebang it works fine for me when executing from a shell that's already using the correct rvm/gemset--don't see any reason it shouldn't work. Commented Oct 27, 2011 at 20:57
  • @Dave Newton: Thanks Dave, that did it! I thought the #!/bin/bash was mandatory for every .sh script... Also, the "cd" turns out to be unnecessary since the .sh file is already in the app root folder. No, I'm not using RVM or anything. Don't forget to add your answer below if you want the karma ;-) Commented Oct 27, 2011 at 21:07

2 Answers 2

1

Try

exec "rails g model my_model name:string accepted:boolean"
Sign up to request clarification or add additional context in comments.

Comments

0

To make sure it's executing in the same context your shell is in, remove the shebang to avoid starting up another bash which may or may not be the same as your current shell.

If you're using rvm/similar, you'd need to either (a) have a default, (b) specify version/gemset, or (c) rely on rvm-like cd fudgery.

Otherwise, should work just fine--it is for me (w/o the shebang, so it'll use whatever current rvm environment I'm in).

Comments

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.