"unknown encoding name" when trying to install Ruby on Rails - ruby-on-rails

I'm trying to install Ruby on Rails, but when I want to use Ruby, install bundle, or create a Rails app, I get this error:
C:/Ruby22-x64/lib/ruby/2.2.0/win32/registry.rb:71:in `find': unknown encoding name - CP720 (ArgumentError)
from C:/Ruby22-x64/lib/ruby/2.2.0/win32/registry.rb:71:in `<module:Win32>'
from C:/Ruby22-x64/lib/ruby/2.2.0/win32/registry.rb:3:in `<top (required)>'
from C:/Ruby22-x64/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/Ruby22-x64/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from dk.rb:1:in `<main>'

Welcome to Stack Overflow! Very glad that you decided to try Ruby and Rails.
Long story short, you're on Windows and there's a lot of caveats to get the Ruby on Rails stack running on this OS. I think you probably tried to install Ruby just by itself... Could you please try removing that and installing the bundle from http://railsinstaller.org/en instead? It will save you a lot of headaches like these in the long run. I've used it and it's a very well thought out package.
Let me know how it works out for you, cheers!

this is because of the default code page of your command terminal.
use the below command to change the code page to Windows-1252 and you will not longer get that error
chcp 1252

Related

Ruby-on-rails cannot connect to mysql2; Windows 10

I'm on Windows 10 and am a complete beginner programmer. I am using Ruby 2.4.2, Rails 5.1.4 and am following a Lynda course on how to run Rails 5 on Windows.
There's a part near the end where the tutor says to enter:
>rails db:schema:dump
to test whether you've established a connection to the MySQL by create a file inside the created project.
This is what I get when I enter the above command:
C:\Users\notmyactualuser\Documents\Sites\demo_project>rails db:schema:dump
rails aborted!
LoadError: cannot load such file -- mysql2/2.4/mysql2
C:/Users/notmyactualuser/Documents/Sites/demo_project/config/application.rb:7:in `<top (required)>'
C:/Users/notmyactualuser/Documents/Sites/demo_project/Rakefile:4:in `require_relative'
C:/Users/notmyactualuser/Documents/Sites/demo_project/Rakefile:4:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
(See full trace by running task with --trace)
The tutor doesn't address what to do with potential errors and I can't seem to find an answer. I want to build a login form using RoR and am trying to grasp the basics (clearly failing). If possible, can I get help with the above and be directed to an easy, simple, "how-to" on building a login form?
Thanks a lot.
P.S. My first post, so please go easy on me, lol.
UPDATE: So I used the command on CMD and it looks like it's successful. Can somebody point me to how to get it working with Rails?
UPDATE 2: I put in the command that Hoa requested and I got this:
ERROR: "bundle install" was called with arguments ["mysql2"]
Usage: "bundle install [OPTIONS]"
UPDATE 3: I did as Satishkakumar said and I got this:
You've installed the binary version of mysql2.
It was built using MySQL Connector/C version 6.1.6.
It's recommended to use the exact same version to avoid potential issues.
At the time of building this gem, the necessary DLL files were retrieved from:
http://cdn.mysql.com/Downloads/Connector-C/mysql-connector-c-6.1.6-win32.zip
This gem includes vendor/libmysql.dll with redistribution notice in vendor/README.
======================================================================================================
Looks like it's all sorted now? Please let me know if there's any more.
I think its issue of installing mysql2 gem in system. Follow below steps to install.
In Gemfile add the line
gem 'mysql2', '0.3.21'
And run bundle install from project folder in CMD.
bundle install mysql2
This might solve your issue. Let me know in comment section if your issue still persists.

Rails Web application could not be started

Getting this error even when I create a new project. I installed Ruby and RoR through RVM
cannot load such file -- /var/lib/gems/2.3.0/gems/passenger-5.0.30/src/ruby_supportlib/phusion_passenger (LoadError)
/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/var/lib/gems/2.3.0/gems/passenger-5.0.30/src/helper-scripts/rack-preloader.rb:74:in `init_passenger'
/var/lib/gems/2.3.0/gems/passenger-5.0.30/src/helper-scripts/rack-preloader.rb:155:in `<module:App>'
/var/lib/gems/2.3.0/gems/passenger-5.0.30/src/helper-scripts/rack-preloader.rb:30:in `<module:PhusionPassenger>'
/var/lib/gems/2.3.0/gems/passenger-5.0.30/src/helper-scripts/rack-preloader.rb:29:in `<main>'
I think I found that the problem is in the directory of the gems. I do not know how to change it on Ubuntu
I would first try to understand if you have a problem with the app or the environment.
Try to run the simplest app by:
rails new simple_app
if it doesn't work - the problem is the environment.
if it does work - probably you have some problem with the initializers or config files
Let us know how it works for you!
Have you try gem install passenger ?
or gem install bundler
Your error message:
cannot load such file -- /var/lib/gems/2.3.0/gems/passenger-5.0.30/src/ruby_supportlib/phusion_passenger (LoadError)
Suggests a permission problem with files in the gem /var/lib/gems/2.3.0/gems/passenger-5.0.30. Either, the files don't exist, or they aren't readable.
If you query the permissions for that file (make sure to append '.rb'):
ls -l /var/lib/gems/2.3.0/gems/passenger-5.0.30/src/ruby_supportlib/phusion_passenger.rb
You'll probably find it's not world readable, or at least not readable by the web server process' user. If it doesn't exist, then you should reinstall.
I saw this error on a system that had a umask of 0066, which caused passenger's gem files to be root:root with mode -rw-------.

Rails Console not loading? y (Errno::ENOENT)

I'm all of the sudden getting the follow error message when I try to load the rails console. I just recently switched databases to postgres, which has given me a slew of problems (although I must admit I like it a lot better than mysql!), so I'm assuming this is related to that. Any ideas?
y (Errno::ENOENT)/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in `require': No such file or directory - /usr/local/lib/?
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in `block in require'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:236:in `load_dependency'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in `require'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/processing.rb:3:in `<top (required)>'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in `require'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in `block in require'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:236:in `load_dependency'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in `require'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:5:in `<top (required)>'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in `require'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in `block in require'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:236:in `load_dependency'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in `require'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/environment.rb:1:in `<top (required)>'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/actionpack-3.2.10/lib/sprockets/railtie.rb:23:in `block in <class:Railtie>'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.10/lib/rails/initializable.rb:30:in `instance_exec'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.10/lib/rails/initializable.rb:30:in `run'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.10/lib/rails/initializable.rb:55:in `block in run_initializers'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.10/lib/rails/initializable.rb:54:in `each'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.10/lib/rails/initializable.rb:54:in `run_initializers'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.10/lib/rails/application.rb:136:in `initialize!'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.10/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/benyorke/rubystore/config/environment.rb:6:in `<top (required)>'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.10/lib/rails/application.rb:103:in `require'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.10/lib/rails/application.rb:103:in `require_environment!'
from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.10/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I believe this might be a bug with Ruby 1.9.3-p327 that just got fixed by Ruby 1.9.3-p385. Does upgrading to 1.9.3-p385 fix it for you?
What seems peculiar in this error message, and is similar to issues I've been having, is the question mark at the end of the path: No such file or directory - /usr/local/lib/?. I've been getting similar strange error messages related to ruby's require and paths with question marks, at symbols, or other random characters at the end of paths after upgrading to 1.9.3-p327 from 1.9.3-p194 a few weeks ago. However, the issues have been extremely sporadic, and around the same time we experienced some hardware failures, so it's been tough to track down.
Today the issue started happening consistently in one specific context, so I was able to do some additional debugging. Updating to 1.9.3-p385 seems to have fixed it, but given the sporadic nature of the issues I've been experiencing, I'm not entirely 100% this is actually the fix. I'm also not entirely sure if this is the same issue you're having. The mysterious question mark in the path just makes it appear like it might be related. Here are a couple examples of the type of errors we were getting:
No such file or directory - /srv/shared/rails/internal/admin/vendor/bun#
No such file or directory - /srv/shared/rails/internal/admin/vendor?
If it's at all related to the same issues I've been experiencing, but the 1.9.3-p385 upgrade doesn't fix it, a few other notes or things to explore:
I was able to reproduce this problem today on 1.9.3-p327 and 1.9.3-p374. However, the problem didn't seem present on 1.9.3-p194, 1.9.3-p286, and 1.9.3-p385.
Are you using symlinks anywhere in in your gem load path? For example, we use Bundler to install gems into a local vendor/bundle path inside each application. But the vendor/bundle is actually a symlink to another location (this is related to a Capistrano deployment setup). I believe the symlink was possibly playing a role. In today's tests, if I wasn't using a symlink, the problem disappeared on all versions of ruby.
Do you use bundler-exec? On another occasion where this problem was happening somewhat sporadically, bypassing the aliases bundler-exec also seemed to magically fix things, but today's problem wasn't even touching bundler-exec, so I'm not too sure.
Most of the time our problem was very random (it would go away after a few attempts of running the same command), but on a few occasions, the problem would persist for an hour or more before disappearing.
Some information about our systems:
64bit RedHat Enterprise Linux 6
Bundler 1.2.3
Rubygems 1.2.5 (also happened under 1.2.4)
rbenv
But like I said, this issue also happened to coincide with some hardware disk failures and general server wonkiness on our end, so I haven't really been certain if this was a Ruby issue or what's been going on. But here's to hoping 1.9.3-p385 actually fixes it.
Sorry for not updating this thread - I have actually been working on this in the background for a few weeks now. I couldn't find ANY information on this online, so I'm going to post as detailed of a solution as I can.
The Issues
The issues I was having was that I could not access rails console, and I had to manually start the postgres server every-time I restarted my machine. My solutions to that, as I have worked with this for a few weeks were
In regards to the console I used herokus console. By pushing my app to heroku (which is free) not only could I view it on the web (any machine) but on my machine I could run
$ heroku run console
and get access to a console. Now this isn't a perfect solution in anyway as I can't manipulate data on my machine but it saved me many times
In regards to the server I ran
$ brew info postgres
which gave me the commands to manually restart the server
You should reload postgresql:
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
The Solution
To be honest, I have run every command I can find dozens of times, and just today got it working. I don't know if I was making typos, doing it in an ineffective order, mixing up pg/postgres/postgresql or what but what I did below worked
When using this solution, it will erase all databases. Migrations will be able to rebuild the structure, but any data will be lost
1. Updated Homebrew
$ brew update
If you don't have home-brew, check out this page for instructions to install (saved my neck with many things, including minimagick imagemagick and postgres!): Link
2. Removed postgresql
$ brew rm postgresql --force
3. Installed postgreql
$ brew install postgresql
This is the first step to reference postgres. When looking online, I ran across commands that used postgresql, postgres, and pg. Postgresql refers to the actually PostgreSQL program. postgres and pg are ruby gems, which we will get to later
4. Ran suggested commands
After running "$ brew install postgres" there is a lot of information given to you. Make sure to read through it, as it will suggest what commands to run. Use these suggestions to find the commands I reference below.
If you need to access this information later simply run
$ brew info postgresql
To initialize the database
$ initdb file/path
Set up the autolauncher
$ cp file/path ~ LaunchAgents/file/path
Launch postgresql initially
$ launchctl load file/path
$ pg_ctl-D file/oath
5. Download Postgres.app
Although to my knowledge this seems redundant, this is what got it to work on my mac. visit http://postgresapp.com to download
6. Install gems
There are two gems - postgres and pg. I required pg in my gemfile and ran a bundle install command, however it still gave me issues until I installed postgres on my machine - even though it is not required in my gemfile, rails console wont seem to work without it atleast installed
In the gem file
gem 'pg'
Run a bundle install command in a terminal window
$ bundle install
Sudo install the postgres gem
$ sudo gem install postgres
At this point everything should be working. You should be able to restart the machine and not have any problems!

Trying to install rails- EISDIR error

I'm new to programming and am trying to set up Ruby on Rails using Michael Hartl's tutorial via Terminal on a Mac running Snow Leopard, but I'm a bit stuck on this part. I've tried using rvm 1.9.2, without any luck, and haven't been able to find anything googling. Any help would be appreciated!
Thanks!
CZom$ gem install rails -v 3.2.3
/Users/CZom/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:253:in `read': Is a directory - /Users/CZom/.gemrc (Errno::EISDIR)
from /Users/CZom/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:253:in `load_file'
from /Users/CZom/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:191:in `initialize'
from /Users/CZom/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/gem_runner.rb:78:in `new'
from /Users/CZom/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/gem_runner.rb:78:in `do_configuration'
from /Users/CZom/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/gem_runner.rb:51:in `run'
from /Users/CZom/.rvm/rubies/ruby-1.9.3-p194/bin/gem:25:in `<main>'
/Users/CZom/.gemrc should be a user specific config file that gets loaded when executing the gem command. Sounds like in your case it is a directory instead. Rubygems is complaining therefore.
Try to rename /Users/CZom/.gemrc or remove it completely if it isn't needed.

Want to take unit test in rails of 2.2.2, but failed. Could anyone tell me the reason and help me to get the solution?

I was following the Agile Web Development with Rails,Third Edition Chapter 14.
I used the command line in windows and input the command of this:
D:\InstantRails-2.0-win\rails_apps\GraduateDesign\depot>ruby -I test test/unit/
product_test.rb
The error message shows below:
D:/InstantRails-2.0-win/rails_apps/GraduateDesign/depot/app/controllers/users_co
ntroller.rb:48: warning: don't put space before argument parentheses
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/acti
ve_support/dependencies.rb:445:in `load_missing_constant': uninitialized constan
t RUBY_COPYRIGHT (NameError)
from D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2
.2.2/lib/active_support/dependencies.rb:77:in `const_missing'
from D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2
.2.2/lib/active_support/dependencies.rb:89:in `const_missing'
from D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rbx-require-rel
ative-0.0.9/lib/require_relative.rb:51
from D:/InstantRails-2.0-win/ruby/lib/ruby/site_ruby/1.8/rubygems/custom
_require.rb:36:in `gem_original_require'
from D:/InstantRails-2.0-win/ruby/lib/ruby/site_ruby/1.8/rubygems/custom
_require.rb:36:in `require'
from D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2
.2.2/lib/active_support/dependencies.rb:155:in `require'
from D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/linecache-0.45-
x86-mswin32/lib/linecache.rb:66
from D:/InstantRails-2.0-win/ruby/lib/ruby/site_ruby/1.8/rubygems/custom
_require.rb:31:in `gem_original_require'
... 16 levels...
from D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2
.2.2/lib/active_support/dependencies.rb:155:in `require'
from D:/InstantRails-2.0-win/rails_apps/GraduateDesign/depot/test/test_h
elper.rb:3
from test/unit/product_test.rb:1:in `require'
from test/unit/product_test.rb:1
I don't think this is causing the error but you might what to check it out incase you've ignored it.
The first line of the error has this:
warning: don't put space before argument parentheses Line number 48 in users_controller.rb.
The important part of the error message is that rails couldn't find the RUBY_COPYRIGHT constant. This constant is part of ruby itself since 1.8.7 so I think you are using something older.
Given that, you should really think about
Updating your Ruby. The current version is 1.9.3
Using a newer Rails. Version 2.2.2 is seriously outdated. Th current version in 3.2.2.
If your book/documentation insists in these old versions, you should find a better book, especially when first learning Rails. Things have seriously change since Ruby 1.8.6 and Rails 2.2. The fourth edition of Agile Web Development with Rails covers Rails 3.

Resources