Error while running rails on windows 7 - ruby-on-rails

I am trying to set my machine up so I can follow this tutorial: the intro to rails screen-cast i wish i had.
I keep running into issues, most recently the following:
C:/Ruby192/lib/ruby/gems/1.9.1/gems/ansi-1.4.1/lib/ansi/code.rb:5:in `require':
no such file to load -- Win32/Console/ANSI (LoadError)
This occurs when ever I run rails g. (I would like to see if my r spec generator has been added.)
Environment details: Windows 7, ruby 1.9.2p290, rails 3.1.1, rubygems 1.8.15

After you installed "gem install win32console", can you add this gem into your Gemfile file and try to run bundle install again?
Gemfile
gem "win32console", "~> 1.3.0"

RailsInstaller may be your best bet if you're looking for an integrated Windows Rails experience.
It's up-to-date (-ish, doesn't use Ruby 1.9.3) with:
Ruby 1.9.2-p290
Rails 3.1.1
Git 1.7.6
and other useful bits.

Related

Ruby version in the Gemfile

The Ruby on Rails Tutorial by Michael Hartl uses a Gemfile without specifying a Ruby version: the ruby keyword is missing in all the applications.
When I deploy to Heroku I receive the following warning:
remote: ###### WARNING:
remote: You have not declared a Ruby version in your Gemfile.
remote: To set your Ruby version add this line to your Gemfile:
remote: ruby '2.2.4'
remote: # See https://devcenter.heroku.com/articles/ruby-versions for more information.
The tutorial says that "the costs associated with including such an explicit Ruby version number outweigh the (negligible) benefits, so you should ignore this warning for now. The main issue is that keeping your sample app and system in sync with the latest Ruby version can be a huge inconvenience".
I am wondering whether the alternative is to keep the pace with the Ruby version at Heroku (presumably 2.2.4 at present), as the book seems to suggest, or also to specify any Ruby version it suits me. In other words, since I am using Ruby 2.2.1p85 for my application, adding ruby "2.2.1", :patchlevel => "85" would work and make Heroku adjust to this version or rather I am supposed to adjust to Heroku and add as suggested ruby '2.2.4'?
I am using rvm and a specific gemset with a specific Ruby version, for no other reason than trying to use an environment as much close to the tutorial as possible. What is the best practice in a real context? Would you suggest to use the last Ruby version and include it in the Gemfile? Can the Gemfile leave out the Ruby version with no worries?
Please follow the steps to solve
You can check which ruby version is associate with your app by command
heroku run "ruby -v"
It is good to have default version of ruby which is 2.2.4 in order to solve your problem. If your ruby version is older than 2.2.4 then please upgrade it.
after checking/upgrading version You can use the ruby keyword in your app’s Gemfile to specify a particular version of Ruby.
source "https://rubygems.org"
ruby "2.2.4"
You will need to install and update bundler again
$ gem install bundler
$ bundle update
This command:
heroku run rake db:migrate
solved same problem

How do I change the default Rails version that gets used?

ANSWERED (other noobs should read what I did):
Thanks to those who answered, but I think I know why it had still been defaulting to the system ruby earlier. I started a shell session and installed rbenv, then install ruby-build for rbenv, then install ruby 2.1.2 and ran rbenv global 2.1.2 Then I installed the new version of rails and tried to create a new rails project.
I think the mistake was just that I hadn't started a new shell session and so it defaulted to the rails location it had when the session started, which was with the system ruby. Stupid mistake. Blah.
ORIGINAL POST:
These are my rbenv versions
system
* 2.1.2 (set by /home/ab/.rbenv/version)
and this is what I get when I run
gem list -d rails
rails (4.2.0.beta1, 4.1.1)
Author: David Heinemeier Hansson
Homepage: http://www.rubyonrails.org
License: MIT
Installed at (4.2.0.beta1): /home/ab/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0
(4.1.1): /home/ab/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0
The Hartl tutorial online uses 4.2.0beta1, so I want to use that, but when I try to make a new rails project, it defaults to 4.1.1.
Somebody from this suggested a way to change a default rails version, but the command looks in the wrong location. See here
ab#abpc:~/Code/RailsTutorial$ rails _4.2.0beta1_ -v
/usr/lib/ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find railties (= 4.2.0beta1) amongst [actionmailer-4.1.1, actionpack-4.1.1, actionview-4.1.1, activemodel-4.1.1, activerecord-4.1.1, activesupport-4.1.1, arel-5.0.1.20140414130214, builder-3.2.2, bundler-1.3.5, coffee-rails-4.0.1, coffee-script-2.2.0, coffee-script-source-1.7.0, diff-lcs-1.2.5, erubis-2.7.0, execjs-2.1.0, hike-1.2.3, i18n-0.6.9, jbuilder-2.0.7, jquery-rails-3.1.0, json-1.8.1, libv8-3.16.14.3-x86_64-linux, mail-2.5.4, mime-types-1.25.1, mini_portile-0.6.0, minitest-5.3.4, multi_json-1.10.1, net-http-persistent-2.9, nokogiri-1.6.2.1, polyglot-0.3.5, rack-1.5.2, rack-protection-1.5.3, rack-test-0.6.2, rails-4.1.1, railties-4.1.1, rake-10.3.2, rdoc-4.1.1, rdoc-3.9.4, ref-1.0.5, rspec-2.14.1, rspec-core-2.14.8, rspec-expectations-2.14.5, rspec-mocks-2.14.6, rspec-rails-2.14.2, sass-3.2.19, sass-rails-4.0.3, sdoc-0.4.0, sinatra-1.4.5, spring-1.1.3, sprockets-2.11.0, sprockets-rails-2.1.3, sqlite3-1.3.9, therubyracer-0.12.1, thor-0.19.1, thor-0.18.1.20140116, thread_safe-0.3.4, tilt-1.4.1, treetop-1.4.15, turbolinks-2.2.2, tzinfo-1.2.0, uglifier-2.5.0, webrat-0.7.3] (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 /usr/local/bin/rails:22:in `<main>'
I'm still far from as knowledgeable as I'd like to be, but I can see that "rails" is defaulting to usr/lib/bin/rails and I need to reroute it to ~/.rbenv/versions/2.1.2/lib/ or somewhere around there... not entirely sure where, and I don't know how to get it to do that. Help?
It looks like you are using your system ruby v1.9.1 which is not compatible with rails 4 at all (Rails 4 requires 1.9.3 or higher).
So first you need to set your ruby version using rbenv global 2.1.2 to set it system-wide or rbenv local 2.1.2 if you just want it for this project. I'm not sure if your system will then default to rails-4.1.1 or the newer beta but you can try rails -v to find out. If not, rails _4.2.0.beta1_ new myapp should work.
The Hartl tutorial online uses 4.2.0beta1
Here is what I am seeing:
Install Rails
Once you’ve installed RubyGems, installing Rails should be easy. This
tutorial standardizes on Rails 4.0, which we can install as follows:
$ gem install rails --version 4.0.8
...
but when I try to make a new rails project, it defaults to 4.1.1.
Gemfile:
source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=sample_app2_gems
gem 'rails', '4.0.8'
...
Set the version of rails you want to use in your Gemfile.

Load Error for Ruby on Rails mysql2

Nubie at Ruby on Rails so I wanted to build a "Hello World" style of app to get familiar with RoR. The app I chose, along with tutorial on installation, was Dave Berube's "checkbook" app as in http://www.redhat.com/magazine/025nov06/features/ruby/
Yes it is from 2006 and maybe I have bumped into my errors because RoR has moved on through the years. Anyway, I get errors similar to banditKing with his app on 20th Sept., and many others; I get a persistent error as below.
When I ran RoR without creating my first app, it displayed the initial splash screen which effectively told me to "get working and create sites!" so that was a good start :-)
[running "rails generate migrate InitialSchema" to begin generating the application framework.]
/usr/local/lib/ruby/gems/2.0.0/gems/mysql2-0.3.13/lib/mysql2.rb:8:in `require': cannot load such file -- mysql2/mysql2 (LoadError)
from /usr/local/lib/ruby/gems/2.0.0/gems/mysql2-0.3.13/lib/mysql2.rb:8:in `<top (required)>'
My environment:
RH Enterprise Linux version 6, 64-bit
[root#svr checkbookapp]# which mysql
/usr/bin/mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.1.69 Source distribution
[root#svr checkbookapp]# which ruby
/usr/local/bin/ruby
[root#svr checkbookapp]# ruby -v
ruby 2.0.0p247 (2013-06-27) [x86_64-linux]
Rails version is 4.0.0
[root#svr checkbookapp]# gem list | grep mysql
mysql (2.9.1)
mysql2 (0.3.13)
Start of my app's Gemfile:
source 'https://rubygems.org'
gem 'rails', '4.0.0'
gem 'mysql2'
...
I have added the library path to MySQL path into my .bash_profile as done by banditKing but that has not resolved this error. Have tried re-installing mysql2 gem several times and doing numerous "bundle install" operations. Downloaded and installed the connector 6.1 from the MySQL site and yum install'd the share and the development versions without any difference.
Try updating RubyGems with gem update --system. You should get something like version 2.x. There's a bug with RubyGems 1.8.x on Ruby 2.0 installing gems with c extentions (like mysql2 and nokogiri).

GemNotFoundException

I am receiving this error when trying to run rails server:
$ rails server
/usr/local/Cellar/ruby/1.9.3-p286/lib/ruby/1.9.1/rubygems.rb:317:in `bin_path': can't find gem rails ([">= 0"]) with executable rails (Gem::GemNotFoundException)
from /usr/local/bin/rails:19:in `<main>'
Why does 1.9.3 use 1.9.1 lib folder?
Thanks.
It uses 1.9.1 for compatibility and historical packing reasons. Given the change is only in minor numbers, everything just works. IMO this folder could be called just ../ruby/1.9.

How can I create previous version rails in rails 3?

I've just upgraded my rails version to rails 3.0.
But suddenly I need a new rails app with old version of rails.
I know the new version of rails change command line usage with rails new.
How can I create an old version of Rails in this new Rails 3 environment?
Use the following command:
rails _2.3.5_ new APP_NAME
This will create a rails project with version 2.3.5
Leonid Shevtsov provided instructions for how to do this here.
The easiest way to do it was:
Create the directory for the project
Create a Gemfile there containing
gem "rails", "2.3.9"
gem "sqlite3-ruby", :require => "sqlite3"
Runbundle install
Run bundle exec rails . to create an app in the current path
You don't even need rvm to do this.
If you need to switch back and forth, I would recommend using RVM. You can install different versions of Ruby and each can have its own set of gems. I use my system installed ruby (1.8.6?) on my Mac for Rails 2 dev, and then I installed Ruby 1.9.2 with RVM for my Rails 3 dev. Its as simple as doing this after you have RVM installed:
#install and use 1.9.2 for Rails 3
rvm install 1.9.2
rvm 1.9.2
rails new whatever
#switch back to system installed ruby for Rails 2
rvm system
rails whatever

Resources