如何从Rakefile启动Rails控制台

时间:2017-11-01 06:01:03

标签: ruby-on-rails ruby-on-rails-4 rake rails-console rakefile

我需要能够从rake take中为我的应用启动rails控制台,但我遇到了一些麻烦。我将以下任务添加到我的Rakefile中:

task :console do
  sh 'cd rails-root && rails console'
end

当我运行rake控制台时,我得到输出,好像我输入了“rails new”而不是“rails console”。我还尝试了这个命令的几种不同变体,包括

exec 'cd rails-root && rails console'
sh 'which rails && cd rails-root && bash -l' # and then typing path/to/rails c
load Gem.bin_path('railties', 'rails', '4.2.7.1')
Rails::Command.invoke 'console' # throws an error: uninitialized constant Rails

每个都给出以下输出:

rails console
Usage:
  rails new APP_PATH [options]

Options:
  -r, [--ruby=PATH]                                      # Path to the Ruby binary of your choice
                                                         # Default: /usr/bin/ruby
  -m, [--template=TEMPLATE]                              # Path to some application template (can be a filesystem path or URL)

... truncating some output ...
Runtime options:
  -f, [--force]                    # Overwrite files that already exist
  -p, [--pretend], [--no-pretend]  # Run but do not make any changes
  -q, [--quiet], [--no-quiet]      # Suppress status output
  -s, [--skip], [--no-skip]        # Skip files that already exist

Rails options:
  -h, [--help], [--no-help]        # Show this help message and quit
  -v, [--version], [--no-version]  # Show Rails version number and quit

Description:
    The 'rails new' command creates a new Rails application with a default
    directory structure and configuration at the path you specify.

    You can specify extra command-line arguments to be used every time
    'rails new' runs in the .railsrc configuration file in your home directory.

    Note that the arguments specified in the .railsrc file don't affect the
    defaults values shown above in this help message.

Example:
    rails new ~/Code/Ruby/weblog

    This generates a skeletal Rails installation in ~/Code/Ruby/weblog.
    See the README in the newly created application to get going.

有人有解决方案吗?

0 个答案:

没有答案