Rails 3 Sandbox Console

好久不见. 提交于 2019-12-05 12:52:35

问题


In Rails 2 you're able to run

script/console --sandbox

so you can play with production data and not accidentally break anything.

I can't seem to find the equivalent command for Rails 3. Does anyone know what it is?


回答1:


Easy, type in:

bundle exec rails c -s

and that is it.

$ bundle exec rails c --help
Usage: console [environment] [options]
    -s, --sandbox                    Rollback database modifications on exit.
        --debugger                   Enable ruby-debugging for the console.
        --irb                        DEPRECATED: Invoke `/your/choice/of/ruby script/rails console` instead

It is simple, but, sometimes, if you are not running rails executable using bundle exec, it may, or may not, result in an error. In order to avoid this, ALWAYS use bundle exec.

To quote bundler page (if not documentation):

In some cases, running executables without bundle exec may work, if the executable happens to be installed in your system and does not pull in any gems that conflict with your bundle.

However, this is unreliable and is the source of considerable pain. Even if it looks like it works, it may not work in the future or on another machine.



来源:https://stackoverflow.com/questions/4881646/rails-3-sandbox-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!