1
votes

I'm currently trying to learn Ruby on Rails using the ebook/tutorial by Michael Hartl (https://www.railstutorial.org/book/), and everything was running fine until section 2.3 on generating the scaffold for Microposts.

Executing

$ rails generate scaffold Micropost content:text user_id:integer

Resulted in the following error:

c:/RailsInstaller/Ruby2.0.0/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:126:in require': cannot load such file - - rails/cli (LoadError) from c:/RailsInstaller/Ruby2.0.0/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:126:in require' from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.2.2/bin/rails:9:in <top (required)>' from c:/RailsInstaller/Ruby2.0.0/bin/rails:23:inload' from c:/RailsInstaller/Ruby2.0.0/bin/rails:23:in `'

I've tried uninstalling/reinstalling rails and railties, gem clean, and a complete reinstall of Ruby 2.0, but the problem still persists. (Reinstalling rails got the rails -v command working again but starting up rails server or rails generate kicked back the error again). Any help would be greatly appreciated :).

Edit to add:

If it helps, my Gemfile also looks like

source 'https://rubygems.org'

gem 'rails', '4.2.2' gem 'sass-rails', '5.0.2' gem 'uglifier', '2.5.3' gem 'coffee-rails', '4.1.0' gem 'jquery-rails', '4.0.3' gem 'turbolinks', '2.3.0' gem 'jbuilder', '2.2.3' gem 'sdoc', '0.4.0', group: :doc

group :development, :test do gem 'sqlite3', '1.3.9' gem 'byebug', '3.4.0' gem 'web-console', '2.0.0.beta3' gem 'spring', '1.1.3' end group :production do gem 'pg', '0.17.1' gem 'rails_12factor', '0.0.2' end

1
did you see this SO post? stackoverflow.com/questions/30083446/…, It suggests running a bundle install.Enermis
Yes I've tried bundle installvward
Running rails -v after rails install and bundle install is giving me: bin/rails:4:in require': cannot load such file -- rails/commands (LoadError) from bin/rails:4:in <main>'vward

1 Answers

3
votes

I get that message when Rails is not installed at the system level. Since you're using bundler, execute the rails command in the context of the bundle using:

bundle exec rails generate scaffold Micropost content:text user_id:integer