开发者

script/rails vs rails

I'm writing a tutorial where I demo some rails commands. On my machine开发者_JS百科 rails and script/rails both work equally well. Is there a "preferred" form? Which of the two works more universally?


When you run the rails executable within a Rails 3 application, it looks for the script/rails file and, if it's present, executes that file with the arguments you passed to rails.

The reason why you'd use rails over script/rails generally falls down to the fact that it's shorter.

One more thing to note, there's also the rails c command which, in a Rails 2 application, will generate an application folder called c inside the current directory. Using script/rails, this wouldn't happen; instead it would complain that the script/rails doesn't exist.


In Rails 3 it should be just rails.


"rails" will show all about the script usage:

Usage: rails COMMAND [ARGS]

The most common rails commands are:
 generate    Generate new code (short-cut alias: "g")
 console     Start the Rails console (short-cut alias: "c")
 server      Start the Rails server (short-cut alias: "s")
 dbconsole   Start a console for the database specified in config/database.yml
             (short-cut alias: "db")
 new         Create a new Rails application. "rails new my_app" creates a
             new application called MyApp in "./my_app"

In addition to those, there are:
 application  Generate the Rails application code
 destroy      Undo code generated with "generate"
 benchmarker  See how fast a piece of code runs
 profiler     Get profile information from a piece of code
 plugin       Install a plugin
 runner       Run a piece of code in the application environment

All commands can be run with -h for more information.


If you are using Bundler, it is actually safer to say

bundle exec rails

as then you are assured of running the version of rails that is in your application's bundle. The same could be said for

bundle exec rake


In window console we have to write ruby script/server but on Ubuntu script/server is enough

rails s and rails c for rail3


You should write just Rails not because is preferred, but just because it's going to become the standard, from here on. script/rails was used in the previous version of rails and it is deprecated right now.

However both command have the same effects in this moment, there is nothing you can't do using rails instead script/rails


script/rails is accessible only in the project application folder. Specifically using this would interrupt the OS's attempt to locate rails from the environment path and may raise an error (as it did on my PC). To create a new Rails App, script/rails won't work but rails would. I suggest you stick to the rails command.

Other commands such as script/generate, script/server, script/console have all become arguments of the rails call.


In rails 3 it should be

rails

...


rails s or rails g scaffold look for script/rails and just pass your arguments in. rails is generally prefered because it's shorter and quicker to type. However, if someone tries to use rails s or rails c in a rails 2.X app it'll add another application folder of that name since the rails command in 2.X generates an application.

If your demo is designed to run on Rails 3 only use rails ... if it's for more general make sure to mention the rails 2 uses script/server ... not rails ...


script/rails commands are for Rails 2. Rails 3 uses rails. script/ commands don't work on my installation.


rails community is giving away much options to make the life easier of devs. The command rails do the same thing and is being used by lots of devs. Due to same reason rails is very popular.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜