简体   繁体   中英

There was an error while trying to load the gem 'rails-api'. (Bundler::GemRequireError)

I am working with Rails 5.0.0.beta3 and creating a rails-api. when i run

rails-api generate scaffold user email:string password:string auth_token:string

it shows the error

.rvm/gems/ruby-2.2.3/gems/bundler-1.11.2/lib/bundler/runtime.rb:80:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'rails-api'. (Bundler::GemRequireError)
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `each'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `block in require'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `each'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `require'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.2/lib/bundler.rb:99:in `require'
from /home/ahsanul/Documents/rails-api/my_blog/config/application.rb:7:in `<top (required)>'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/spring-1.7.1/lib/spring/application.rb:82:in `require'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/spring-1.7.1/lib/spring/application.rb:82:in `preload'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/spring-1.7.1/lib/spring/application.rb:143:in `serve'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/spring-1.7.1/lib/spring/application.rb:131:in `block in run'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/spring-1.7.1/lib/spring/application.rb:125:in `loop'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/spring-1.7.1/lib/spring/application.rb:125:in `run'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/spring-1.7.1/lib/spring/application/boot.rb:19:in `<top (required)>'
from /home/ahsanul/.rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /home/ahsanul/.rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from -e:1:in `<main>'

How can i resolve the problem?

You don't need to include rails-api gem in your Rails 5 app's Gemfile. It's already merged into Rails 5.

Reference

I tried all the above suggestion from Babar but didn't work, so i tried one little thing that work which is adding gem 'listen' to the gem file. it works for me!!

rails-api generate scaffold user email:string password:string auth_token:string

No need of writing rails-api, just use rails. Rails::API has been merged into Rails 5.0, so no need of gem 'rails-api'.So remove it from gemfile.After than you may get error when you try to migrate.So you have to include listen gem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM