Rails 101 - Unable to run script of Scaffold commands
I apologize for what I know is a basic question, but my searches have not found an answer so I thought I would try the forum. I am starting a RoR project and would like to create a script for all of the scaffolding scripts.
Ruby 2.3.3 Rails: 4.2.7 RubyMine 2016.3
For example, I created the following file under <project>/scripts Scaffold.txt
rails scaffold Tenant name:string description:text active:boolean
rails scaffold User username:string description:text active:boolean
I then select Tools\Run Rails Script... select the file and I get the following error:
/.rvm/rubies/ruby-2.3.3/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /RubymineProjects/MyRoR/scripts/TestScript.txt
-e:1:in `load': /RubymineProjects/MyRoR/scripts/TestScript.txt:1: syntax error, unexpected tLABEL, expecting keyword_do or '{' or '(' (SyntaxError)
rails scaffold Tenant name:string description:text active:boolean
^
/RubymineProjects/MyRoR/scripts/TestScript.txt:2: syntax error, unexpected tLABEL, expecting keyword_do or '{' or '('
rails scaffold User username:string description:text active:boolean
^
from -e:1:in `<main>'
Based on that error I assume I have a basic misunderstanding of what the script file syntax should be. I thought it was a list of rails commands. I am able to generate the scaffold if I run each command through the Rails Generator, so my environment is working properly.
Any guidance would be greatly appreciated.
-Thanks in advance
请先登录再写评论。
I also tried variations of the script such as:
rails generate scaffold ...
or
generate scaffold ...
and I got the same error message
Hello,
you can have your own Ruby scripts but the command will look like `/.rvm/rubies/ruby-2.3.3/bin/ruby /PATH_TO_THE_SCRIPT/TestScript.rb` so you can also check how your script runs by doing it manually from the Terminal for example. As for scaffold, you can run Tools | Run Rails Script, type `rails` as the script name and `generate scaffold Tenant name:string description:text active:boolean` as the argument.