Visual Studio Code can't access rails -v - ruby-on-rails

I don't know if it's related but I'd like to inform I use ASDF (https://github.com/asdf-vm/asdf) to versioning my PLs.
My problem is: I can't access rails commands on VSC terminal.
I get:
$ rails -v
Traceback (most recent call last):
4: from bin/rails:3:in `<main>'
3: from bin/rails:3:in `require_relative'
2: from /home/italo/Área de Trabalho/code-saga/3/cookbook_parte1/config/boot.rb:3:in `<top (required)>'
1: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- bundler/setup (LoadError)
This doens't happen when I do 'ruby -v'.
I'm using ubuntu 18.04 and when I run both commands (rails -v, ruby -v) in ubuntu terminal, everything works fine.

I installed the ruby plugin in vsc and restarted the terminal. Worked!

Related

Can't update RubyGems or install RubyGems from source

When I attempt to run sudo update_rubygems or sudo gem update --system I get similar errors:
Installing RubyGems 3.2.3
Traceback (most recent call last):
4: from setup.rb:23:in `<main>'
3: from setup.rb:23:in `require'
2: from /var/lib/gems/2.5.0/gems/rubygems-update-3.2.3/lib/rubygems.rb:1348:in `<top (required)>'
1: from /var/lib/gems/2.5.0/gems/rubygems-update-3.2.3/lib/rubygems.rb:1348:in `require'
/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:43:in `<top (required)>': uninitialized constant Gem::BasicSpecification (NameError)
I've tried reinstalling RubyGems 3.2.3 from source using ruby setup.rb and I get essentially the same error.
Traceback (most recent call last):
4: from setup.rb:23:in `<main>'
3: from setup.rb:23:in `require'
2: from /home/izaguirrejoe/Downloads/rubygems-3.2.3/lib/rubygems.rb:1348:in `<top (required)>'
1: from /home/izaguirrejoe/Downloads/rubygems-3.2.3/lib/rubygems.rb:1348:in `require'
/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:43:in `<top (required)>': uninitialized constant Gem::BasicSpecification (NameError)
One clue: I'm a noob and I ran sudo apt-get autoremove and it removed a bunch of Ruby-looking stuff. Maybe that was it? I did that, updated Vim to the newest version and installed YouCompleteMe, and now my existing rails app is not working. New rails apps work just fine, but I'd like to be able to update RubyGems. I'm on the verge of just reinstalling Debian and starting over, this is frustrating.
Another clue: hours of research has revealed that I may have two versions of Ruby installed. When I run which -a ruby I get
/usr/bin/ruby
/bin/ruby

require 'bundler' error, cannot load such file -- bundler (LoadError)

Unable to run rails console, rails -v etc. Already tried all of the solutions, reinstalled ruby, installed bundler but neither worked for me.
Traceback (most recent call last):
4: from bin/rails:3:in `<main>'
3: from bin/rails:3:in `load'
2: from /var/www/App/releases/XXXXXXXXXXX/bin/spring:8:in `<top (required)>'
1: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- bundler (LoadError)
A few days back I also land up into the same issue, I think it was due to spring caching some gems and configurations. I fixed it by running bundle pristine.
This restores installed gems based on the Gemfile.lock to pristine condition from files located in the gem cache.

Rails console not working even after updates

I am trying to run rails console. I have tried everything suggested on SO. I have libreadline-6 installed. My ruby version is 2.1.1 and irb is 0.9.6.
/home/xamroc/.rbenv/versions/2.1.1/lib/ruby/2.1.0/irb/completion.rb:9:in `require': cannot load such file -- readline (LoadError)
from /home/xamroc/.rbenv/versions/2.1.1/lib/ruby/2.1.0/irb/completion.rb:9:in `<top (required)>'
from /home/xamroc/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/railties-4.0.3/lib/rails/commands/console.rb:3:in `require'
from /home/xamroc/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/railties-4.0.3/lib/rails/commands/console.rb:3:in `<top (required)>'
from /home/xamroc/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/railties-4.0.3/lib/rails/commands.rb:51:in `require'
from /home/xamroc/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/railties-4.0.3/lib/rails/commands.rb:51:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
Any suggestions?
Also, I am using rbenv to manage my ruby versions.
You need to install libreadline and also the -dev package and then you need to recompile ruby. When your using rvm you should always run
rvm requirements
first and then download and compile ruby. If your using rvm then you can run
rvm reinstall <version>
to do this.
// Also see: http://vvv.tobiassjosten.net/ruby/readline-in-ruby-with-rbenv/

Error Starting Rails Server on New Local Machine Running Existing Rails App

When I run
./script/server
I get the following error message and I can't seem to find how to fix the problem. The folder is on my Desktop and is a checkout from an SVN Repository on a new machine running MacOSX 10.8.3.
/Users/martin/Desktop/[FOLDER NAME]/config/boot.rb:89:in `load_rubygems': undefined method `set_paths' for Gem:Module (NoMethodError)
from /Users/martin/Desktop/[FOLDER NAME]/config/boot.rb:52:in `load_initializer'
from /Users/martin/Desktop/[FOLDER NAME]/config/boot.rb:39:in `run'
from /Users/martin/Desktop/[FOLDER NAME]/config/boot.rb:11:in `boot!'
from /Users/martin/Desktop/[FOLDER NAME]/config/boot.rb:115:in `<top (required)>'
from /Users/martin/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /Users/martin/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from ./script/server:2:in `<main>'
Does anyone have any ideas on how to fix/troubleshoot?
If I run which -a ruby I get:
/Users/martin/.rbenv/shims/ruby
/Users/martin/.rbenv/shims/ruby
/Users/martin/.rbenv/shims/ruby
/Users/martin/.rbenv/shims/ruby
/Users/martin/.rbenv/shims/ruby
/usr/bin/ruby
rails -v
Rails 4.0.0
ruby -v
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.3.0]
Running script/server gives a different error
/Users/martin/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- script/../config/boot (LoadError)
from /Users/martin/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from script/server:2:in `<main>'

Problems running rails server

I just installed the rails env using the Rails installer on my Mac OSX 10.7.4.
I create a project using the "rails new" command.
When I try to run the "rails server" command I get this message:
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/rails-2.3.14/lib/rails_generator/options.rb:32:in `default_options': undefined method `write_inheritable_attribute' for Rails::Generator::Base:Class (NoMethodError)
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/rails-2.3.14/lib/rails_generator/base.rb:90:in `<class:Base>'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/rails-2.3.14/lib/rails_generator/base.rb:85:in `<module:Generator>'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/rails-2.3.14/lib/rails_generator/base.rb:48:in `<module:Rails>'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/rails-2.3.14/lib/rails_generator/base.rb:6:in `<top (required)>'
from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/rails-2.3.14/lib/rails_generator.rb:37:in `<top (required)>'
from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/rails-2.3.14/bin/rails:15:in `<top (required)>'
from /usr/local/rvm/gems/ruby-1.9.3-p194/bin/rails:23:in `load'
from /usr/local/rvm/gems/ruby-1.9.3-p194/bin/rails:23:in `<main>'
When I run the $ ruby -v and $ gem -v, I get "ruby 1.9.3p194" and "1.8.24" respectively. What am I missing here? How can I get this server to run?
It looks like you are trying to use a Rails 3.x command with Rails 2.3. Pre 3.0 you have to use the server script.
From within your application directory run:
./script/server
Install rails as a gem, gem install rails . As your are using rvm, the folder path displayed here shows rails 2.3.4, while you tried to run rails server . Check/change the rails version in your gem file and then do bundle install.

Resources