Rails生成命令无法正常工作

3

我正在尝试使用rails生成器创建迁移,但当我运行rails g migration create_meetups_table时,我得到以下输出:

Could not find slop-3.4.7 in any of the sources
Run `bundle install` to install missing gems.

我手动安装了gem,然后再次运行bundle install,得到以下输出:

Using i18n 0.6.9
Using json 1.8.1
Using minitest 5.3.4
Using thread_safe 0.3.4
Using builder 3.2.2
Using erubis 2.7.0
Using rake 10.3.2
Using rack 1.5.2
Using polyglot 0.3.5
Using mime-types 1.25.1
Using arel 5.0.1.20140414130214
Using bcrypt 3.1.7
Using coderay 1.1.0
Using coffee-script-source 1.7.0
Using execjs 2.2.0
Using thor 0.19.1
Using orm_adapter 0.5.0
Using geocoder 1.2.2
Using hike 1.2.3
Using multi_json 1.10.1
Using method_source 0.8.2
Using pg 0.17.1
Using slop 3.4.7
Using bundler 1.6.2
Using tilt 1.4.1
Using sass 3.2.19
Using spring 1.1.3
Using rdoc 4.1.1
Using tzinfo 1.2.1
Using rack-test 0.6.2
Using warden 1.2.3
Using treetop 1.4.15
Using coffee-script 2.2.0
Using uglifier 2.5.1
Using pry 0.9.12.4
Using sprockets 2.11.0
Using sdoc 0.4.0
Using activesupport 4.1.1
Using mail 2.5.4
Using actionview 4.1.1
Using activemodel 4.1.1
Using jbuilder 2.1.0
Using actionpack 4.1.1
Using activerecord 4.1.1
Using actionmailer 4.1.1
Using railties 4.1.1
Using sprockets-rails 2.1.3
Using coffee-rails 4.0.1
Using devise 3.2.4
Using jquery-rails 3.1.0
Using rails 4.1.1
Using sass-rails 4.0.3
Using rMeetup 1.0.1 from git://github.com/tannermares/rmeetup.git (at master)
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.

我可以清楚地看到宝石正在进行捆绑。我可以运行其他命令来启动应用程序和控制台,但无法运行生成迁移的命令。有没有想法如何解决这个问题?我已经尝试删除Ruby的安装并重新安装,但没有帮助。


从您的项目根目录中运行 bundle install 命令,然后尝试运行。它会正常工作。 - Arup Rakshit
@ArupRakshit 我已经尝试过了,但没有成功。 - rigelstpierre
如果你尝试使用 bundle exec rails...,有什么不同吗?你是否使用类似于 rvmrbenv 的工具? - Sam Starling
2个回答

10

我认为 Spring 的行为不正确,并且没有正确地重新要求 gem 包。

使用 bin/spring status 检查 Spring 的状态。 如果正在运行,请尝试使用 bin/spring stop 停止它。 如果没有运行,请检查是否有任何孤立的 Spring 进程可能会造成问题:

ps aux | grep spring

我不确定 Spring 为什么会这样,但是将其关闭后问题得到解决。 我无法再次复制以进一步调查。


Spring停止和Spring服务器有所帮助。 - Marat

2
您可能正在使用错误的Rails版本。在您的rails命令前加上bundle exec应该可以解决问题。
rails g migration create_meetups_table

变得

bundle exec rails g migration create_meetups_table

同时将这个 gem 添加到你的 Gemfile.rb 文件中,并运行 bundle install 命令,这样当你使用 bundler 执行 rails 命令时,bundler 就会知道正确的 gems。
对于长期来说,使用 RVM 或 RBENV 可能是更好的解决方案。 https://rvm.io/ https://github.com/sstephenson/rbenv

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接