Rails Console not running? - ruby-on-rails

just started learning programming from Hartl's tutorial. I updated Ruby to 2.3.1 recently (using Rails 4.2.6) and I'm trying to run the console but I'm getting this error:
Carloss-MBP:sample_app carlosgrijalva$ rails console
/Users/carlosgrijalva/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require': cannot load such file -- rails/commands (LoadError)
from /Users/carlosgrijalva/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `block in require'
from /Users/carlosgrijalva/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/carlosgrijalva/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require'
from /Users/carlosgrijalva/workspace/sample_app/bin/rails:9:in `<top (required)>'
from /Users/carlosgrijalva/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `load'
from /Users/carlosgrijalva/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `block in load'
from /Users/carlosgrijalva/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/carlosgrijalva/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `load'
from /Users/carlosgrijalva/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/carlosgrijalva/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
Not entirely sure what that means. I notice that it's bringing up Ruby 2.3.0, did I not update Ruby properly? Should I just reinstall the gems?

After installing a new version of Ruby, you need to install your gems as well. If you are using bundler then just run:
# In your folder with `Gemfile` file.
bundle install

Regarding your ruby question you need to change your ruby version on your system using RVM or RBENV.
With RVM:
rvm use ruby-2.3.1 --default
With RBENV:
rbenv global 2.3.1
Then run:
bundle install

Related

not able to login heroku

i was trying to login to heroku to push my app and until yesterday it was working but now it is giving me errors related to json version.
this is the log created after command heroku login
This is the legacy Heroku CLI. Please install the new CLI from https://cli.heroku.com
c:/RailsInstaller/Ruby2.3.0/lib/ruby/2.3.0/rubygems/specification.rb:2275:in `check_version_conflict': can't activate json-1.8.2, already activated json-1.8.3 (Gem::LoadError)
from c:/RailsInstaller/Ruby2.3.0/lib/ruby/2.3.0/rubygems/specification.rb:1404:in `activate'
from c:/RailsInstaller/Ruby2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:89:in `block in require'
from c:/RailsInstaller/Ruby2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:88:in `each'
from c:/RailsInstaller/Ruby2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:88:in `require'
from c:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/heroku-3.99.1/lib/heroku/cli.rb:16:in `<top (required)>'
from c:/RailsInstaller/Ruby2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from c:/RailsInstaller/Ruby2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from c:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/heroku-3.99.1/bin/heroku:24:in `<top (required)>'
from c:/RailsInstaller/Ruby2.3.0/bin/heroku:22:in `load'
from c:/RailsInstaller/Ruby2.3.0/bin/heroku:22:in `<main>'
my ruby version is 2.3.3 and rails 5.0.3
Thank you
`check_version_conflict': can't activate json-1.8.2, already activated
json-1.8.3 (Gem::LoadError)
This is due to bundler trying to install json-1.8.2 when there is json-1.8.3 already installed. This is because bundler will use Gemfile.lock to install specified gem versions of gems.
You should do gem cleanup and followed by gem update json. This will update the json to latest version in Gemfile.lock and will resolve the problem.

Could not railties in mac os

I had recently followed multiple blogs to completely wipe out rvm, rails and then reinstalled ruby 2.3.0 and rails 5. Made and app using it no issues. But the moment I opened a new terminal window in my machine it was not recognising rails at all as if it was only installed in that particular terminal.
So I just completed my work in that single terminal. Now when I restarted my laptop, I am unable to run the same app. I do not wish to reinstall everything again as I am sure this is a small configuration problem. Why is this happening?
The error message that I am getting now:
/Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/dependency.rb:319:in `to_specs': Could not find 'railties' (>= 0.a) among 30 total gem(s) (Gem::LoadError)
Checked in 'GEM_PATH=/Users/sahil/.rvm/gems/ruby-2.3.1:/Users/sahil/.rvm/gems/ruby-2.3.1#global', execute `gem env` for more information
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/dependency.rb:328:in `to_spec'
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_gem.rb:65:in `gem'
from /Users/sahil/.rbenv/versions/2.3.1/bin/rails:22:in `<main>'
I have already seen other similar questions where they ask to reinstall everything again which I do not want to do as it worked after installing but did not work on system restart.
Now I did gem install rails in one terminal and the app is working again, but if I try to open a new terminal and give the same command rails s, it gives me this error,
Ignoring byebug-9.0.5 because its extensions are not built. Try: gem pristine byebug --version 9.0.5
Ignoring debug_inspector-0.0.2 because its extensions are not built. Try: gem pristine debug_inspector --version 0.0.2
Ignoring nokogiri-1.6.8 because its extensions are not built. Try: gem pristine nokogiri --version 1.6.8
Ignoring byebug-9.0.5 because its extensions are not built. Try: gem pristine byebug --version 9.0.5
Ignoring debug_inspector-0.0.2 because its extensions are not built. Try: gem pristine debug_inspector --version 0.0.2
/Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': incompatible library version - /Users/sahil/.rvm/gems/ruby-2.3.1#global/gems/io-console-0.4.6/lib/io/console.bundle (fatal)
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/user_interaction.rb:9:in `<top (required)>'
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/config_file.rb:8:in `<top (required)>'
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/sahil/.rvm/gems/ruby-2.3.1#global/gems/bundler-1.12.5/lib/bundler/rubygems_integration.rb:4:in `<top (required)>'
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/sahil/.rvm/gems/ruby-2.3.1#global/gems/bundler-1.12.5/lib/bundler/shared_helpers.rb:6:in `<top (required)>'
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/sahil/.rvm/gems/ruby-2.3.1#global/gems/bundler-1.12.5/lib/bundler/setup.rb:2:in `<top (required)>'
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `require'
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `rescue in require'
from /Users/sahil/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:40:in `require'
from /Users/sahil/Documents/work/Development/todoApp/config/boot.rb:3:in `<top (required)>'
from bin/rails:3:in `require_relative'
from bin/rails:3:in `<main>'
You mentioned that you reinstalled ruby 2.3.0 and Rails 5. However it seems rbenv is trying to load your project with ruby 2.3.1.
You should switch to ruby 2.3.0. I guess you should be able to do: rbenv local 2.3.0.
To avoid this from happening again though, you should add a .ruby-version dotfile to your project root and in the file only add 2.3.0.
Hope that works

Ruby sqlite3 gem not found

I recently downloaded Crunchbang and am downloading a Ruby program. I installed Ruby:
apt-get install ruby
apt-get install rubygems
apt-get install sqlite3
When I run the file, I get:
root#crunchbang:/Pentest/NTLMRelay/ZackAttack# ruby zackattack.rb
/usr/lib/ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find sqlite3 (= 1.3.6) amongst [] (Gem::LoadError)
from /usr/lib/ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
from /usr/lib/ruby/1.9.1/rubygems.rb:1231:in `gem'
from /Pentest/NTLMRelay/ZackAttack/lib/zfdb.rb:7:in `<top (required)>'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:60:in `require'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
from /Pentest/NTLMRelay/ZackAttack/clients/ews.rb:9:in `<top (required)>'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:60:in `require'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
from /Pentest/NTLMRelay/ZackAttack/lib/zfclient.rb:6:in `<top (required)>'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:60:in `require'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
from /Pentest/NTLMRelay/ZackAttack/lib/zfhttpd.rb:7:in `<top (required)>'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:60:in `require'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
from zackattack.rb:8:in `<main>'
I am completely at a loss. Help is appreciated/
You need to install ruby gem as well:
gem install sqlite3
If your program has a Gemfile, do:
gem install bundler
bundle install
Another advise, install ruby via RVM, it will save you from a number of headaches.
UPDATE:
Most likely you will also need the following package:
sudo apt-get install libsqlite3-ruby
You can also install the gem as follows using apt:
apt-get install ruby-sqlite3
or in my case:
apt-get install sqlite3-ruby
I would avoid installing Ruby using apt-get because you'll face a lot of problems (versions, gem management, etc) down the road. Use RVM instead.
Remove your apt-get installations (especially if your ruby -v returns something before 1.9) and then follow the instructions at http://rvm.io/rvm/install
RVM will allow you to install multiple Ruby versions and manage your gems more easily.
Once you're done with the rvm installation, do the following:
gem install sqlite3 -v 1.3.6
Once you have RVM running, things should become easier... Don't worry about the extra time you're spending in the beginning, it'll pay off :-)

OpenSSL error when creating a new Rails project

I'm trying to create a new Rails project using the railstutorial.org. However, when I try to create a new app, I get the following error:
User-MacBook-Air:rails_projects user$ rails new first_ap
/user.rvm/rubies/ruby-1.9.3-p448/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': dlopen(/user.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/x86_64-darwin12.5.0/digest/md5.bundle, 9): Library not loaded: /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib (LoadError)
Referenced from: /user.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/x86_64-darwin12.5.0/digest/md5.bundle
Reason: image not found - /user.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/x86_64-darwin12.5.0/digest/md5.bundle
from /user.rvm/rubies/ruby-1.9.3-p448/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /user.rvm/gems/ruby-1.9.3-p448#rails3tutorial2ndEd/gems/railties-3.2.14/lib/rails/generators/app_base.rb:1:in `<top (required)>'
from /user.rvm/rubies/ruby-1.9.3-p448/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /user.rvm/rubies/ruby-1.9.3-p448/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /user.rvm/gems/ruby-1.9.3-p448#rails3tutorial2ndEd/gems/railties-3.2.14/lib/rails/generators/rails/app/app_generator.rb:1:in `<top (required)>'
from /user.rvm/rubies/ruby-1.9.3-p448/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /user.rvm/rubies/ruby-1.9.3-p448/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /user.rvm/gems/ruby-1.9.3-p448#rails3tutorial2ndEd/gems/railties-3.2.14/lib/rails/commands/application.rb:24:in `<top (required)>'
from /user.rvm/rubies/ruby-1.9.3-p448/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /user.rvm/rubies/ruby-1.9.3-p448/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /user.rvm/gems/ruby-1.9.3-p448#rails3tutorial2ndEd/gems/railties-3.2.14/lib/rails/cli.rb:15:in `<top (required)>'
from /user.rvm/rubies/ruby-1.9.3-p448/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /user.rvm/rubies/ruby-1.9.3-p448/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /user.rvm/gems/ruby-1.9.3-p448#rails3tutorial2ndEd/gems/railties-3.2.14/bin/rails:7:in `<top (required)>'
from /user.rvm/gems/ruby-1.9.3-p448#rails3tutorial2ndEd/bin/rails:23:in `load'
from /user.rvm/gems/ruby-1.9.3-p448#rails3tutorial2ndEd/bin/rails:23:in `<main>'
How do I get rid of this OpenSSL error? I am using the following:
Rails 3.2.14
ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-darwin12.5.0]
rvm 1.22.11 (stable) by Wayne E. Seguin <wayneeseguin#gmail.com>, Michal Papis <mpapis#gmail.com> [https://rvm.io/]
Well, there's a very large chance it was overkill but for me uninstalling ruby entirely and then reinstalling it and all the gems that my project uses solved the problem.
If you're using rbenv, the commands that I used were
rbenv uninstall 2.6.3
rbenv install 2.6.3
gem install bundler
gem install rails -v 6.0.2
rbenv rehash
bundle update
Again, this is probably overkill, but it solved the problem after brew install openssl didn't work for me.
If you haven't installed OpenSSL, try installing it with Homebrew
brew install openssl

rails server not starting

I just bundle installed successfully and now I get this error when I start the rails server.
I have already tried to start the server by installing openssl and re-installing rvm.
I'm using rvm 1.8.7 and rails 3.0.10.
rony#linuxmint ~/Documents/trunk $ rails s
/home/rony/.rvm/gems/ruby-1.8.7-p370/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:239:in `require': no such file to load -- openssl (LoadError)
from /home/rony/.rvm/gems/ruby-1.8.7-p370/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:239:in `require'
from /home/rony/.rvm/gems/ruby-1.8.7-p370/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:225:in `load_dependency'
from /home/rony/.rvm/gems/ruby-1.8.7-p370/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:593:in `new_constants_in'
from /home/rony/.rvm/gems/ruby-1.8.7-p370/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:225:in `load_dependency'
from /home/rony/.rvm/gems/ruby-1.8.7-p370/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:239:in `require'
from /home/rony/.rvm/gems/ruby-1.8.7-p370/gems/stripe-1.7.0/lib/stripe.rb:7
from /home/rony/.rvm/gems/ruby-1.8.7-p370#global/gems/bundler-1.2.1/lib/bundler/runtime.rb:68:in `require'
from /home/rony/.rvm/gems/ruby-1.8.7-p370#global/gems/bundler-1.2.1/lib/bundler/runtime.rb:68:in `require'
from /home/rony/.rvm/gems/ruby-1.8.7-p370#global/gems/bundler-1.2.1/lib/bundler/runtime.rb:66:in `each'
from /home/rony/.rvm/gems/ruby-1.8.7-p370#global/gems/bundler-1.2.1/lib/bundler/runtime.rb:66:in `require'
from /home/rony/.rvm/gems/ruby-1.8.7-p370#global/gems/bundler-1.2.1/lib/bundler/runtime.rb:55:in `each'
from /home/rony/.rvm/gems/ruby-1.8.7-p370#global/gems/bundler-1.2.1/lib/bundler/runtime.rb:55:in `require'
from /home/rony/.rvm/gems/ruby-1.8.7-p370#global/gems/bundler-1.2.1/lib/bundler.rb:128:in `require'
from /home/rony/Documents/trunk/config/application.rb:8
from /home/rony/.rvm/gems/ruby-1.8.7-p370/gems/railties-3.0.10/lib/rails/commands.rb:28:in `require'
from /home/rony/.rvm/gems/ruby-1.8.7-p370/gems/railties-3.0.10/lib/rails/commands.rb:28
from /home/rony/.rvm/gems/ruby-1.8.7-p370/gems/railties-3.0.10/lib/rails/commands.rb:27:in `tap'
from /home/rony/.rvm/gems/ruby-1.8.7-p370/gems/railties-3.0.10/lib/rails/commands.rb:27
from script/rails:6:in `require'
from script/rails:6
Ref this
rvm pkg install openssl (older format - rvm package install openssl)
rvm pkg install iconv (older format - rvm package install iconv)
rvm remove 1.9.2
rvm install 1.9.2 -C --with-openssl-dir=$HOME/.rvm/usr,--with-iconv-dir=$HOME/.rvm/usr
Credit to http://www.isnull.com.ar/

Resources