Can't start Ruby On Rails Webbrick server using Mysql2 gem - ruby-on-rails

I just started learning Ruby on Rails and i'm going through Lynda Ruby on Rails 4 Essential Training. So far everything was looking really good (no errors while installing everything), but when i tried to run Webbrick server i get error.
Can someone please help me to debug this server log.
I'm working on windows 8
ruby -v
ruby 2.0.0p481 (2014-05-08) [x64-mingw32]
rails -v
Rails 4.1.5
gem --version mysql2
2.4.1
Because error is too big i'm giving you a link to txt file.
Click here

Okay, you mention you're using Windows, and you're a newbie, so I'll give you some information on how to get the infamous mysql2 gem working on your system (which is likely to be the problem):
MYSQL2
Because Windows does not come with many developer dependencies (including MYSQL), installing gems such as mysql2, rmagick and curl don't work out of the box
Instead, you have to first install the development dependencies (often referred to as "header files") in order to install the gem. This is how you do it with MYSQL2 (by the way, we've written a tutorial about this here)
--
You need to ensure the MYSQL2 gem installs on your Windows system. This is done using 3 steps:
Install the MYSQL C-Connector header files
Install the MYSQL2 gem, referencing the newly installed MYSQL C-Connector files
Copy libmysql.dll from your MYSQL folder to your Ruby folder
Firstly, you need to install the mysql c-connector header files:
Please note you must ALWAYS install the 32 bit version of the C-Connector library, regardless of which version of Windows you're using. Also, you need to install to a file path which has no spaces
Once you've done this, you then need to be able to install the mysql2 gem, whilst referencing the newly installed MYSQL library:
gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:\mysql-connector-path"'
This gives you the ability to install the gem by referencing the files it needs. That's why you need to install the dependencies without any spaces.
If this installs the gem, you then need to copy the libmysql.dll file:
Now this is just a presumption
You need to ensure you have the gem installed in order to get the server running.

There is a patch for the related issue: https://copy.com/CHZ4eT4us6f1/mysql-connector-c-noinstall-6.0.2-winx64.zip where it's discussed in https://github.com/brianmario/mysql2/issues/372
You can download the file at the above link and extract to the disk, assume you unzip to "D:" drive as D:\mysql-connector-c-noinstall-6.0.2-winx64
Try to install mysql2 gem again.
gem install mysql2 --no-rdoc --no-ri -- '--withmysql-dir="D:\mysql-connector-c-noinstall-6.0.2-winx64\bin" --with-mysql-lib="D:\mysql-connector-c-noinstall-6.0.2-winx64\lib" --with-mysql-include="D:\mysql-connector-c-noinstall-6.0.2-winx64\include"'
Then, copy libmysql.dll file from D:\mysql-connector-c-noinstall-6.0.2-winx64\lib folder to D:\Ruby\bin\ folder.
Finally, try to start rails webrick server again.

Related

NoMethodError: undefined method `split' for nil:NilClass when running "rake native gem" [duplicate]

Being really new to Ruby/Rails, and after attempting to resolve the issue myself this weekend I'm making an attempt to seek advice here.
I have a complete Ruby/Apache/Passenger setup done on FreeBSD, and I'm trying to accomplish the task of using Windows as a Ruby development environment.
So far:
Ruby is installed, v2.0.0p0 (2013-02-24) [x64-ming32]
Rails is installed, v.3.2.12
I have the Ruby dev kit installed and registered.
I have the sqlite3 dll/exe copied to the Ruby "bin" folder (which is also in my path using the "Start Command Prompt with Ruby" console.)
I can start a rails server successfully, and continuing with the http://guides.rubyonrails.org/getting_started.html tutorial to 3.3.
">rake db:create" tells me:
Please install the sqlite3 adapter: gem install activerecord-sqlite3-adapter (
sqlite3 is not part of the bundle. Add it to Gemfile.)
which I have no "understanding" of. Trying to install activerecord-sqlite3-adapter gives me a "Could not find a valid gem..."
">gem install sqlite3" returns:
Building native extensions. This could take a while...
ERROR: Error installing sqlite3:
ERROR: Failed to build gem native extension.
D:/Development/Ruby200-x64/bin/ruby.exe extconf.rb
checking for sqlite3.h... *** extconf.rb failed ***
Right now I'm stuck at the point where I don't even know what state my Ruby on Windows installation is in. I'm trying to follow the main Rails tutorial and it doesn't specify any of these issues (probably because Ruby on Windows seems to be a natural pain for a lot of people.)
What am I missing?!? I'm just trying to install sqlite3 for Ruby on Windows, seems simple right?
If I do ">rais db" the SQLite shell is presented:
SQLite version 3.7.15.2 2013-01-09 11:53:05
Similar questions with steps that do not resolve my issue:
Installing SQLite 3.6 On Windows 7
Even though the question has been answered, I want to post my research to help others. I found a lot of information online, but being a Ruby newbie I had a tough time following all. The basic answer comes from the following post https://github.com/luislavena/sqlite3-ruby/issues/82 with instructions by "paulwis" on how to properly install sqlite3 for ruby 2.0.0-p0 and some comments on https://github.com/rails/rails/issues/10150 . So here it is:
Install the Ruby Devkit for your setup (DevKit-mingw64-64-4.7.2-20130224-1432-sfx.exe for me since I use a x64 machine)
Download and extract the autoconf package from Sqlite.org
Run msys.bat (it is inside the ruby devkit root folder)
cd into the path where you downloaded the sqlite source (for example: "cd /c/dev/sqlite3" for path "c:\dev\sqlite3" if you are new to MSYS/MINGW32)
Run "./configure"
Run "make"
Run "make install"
Get the sqlite3 gem again, this time specifying the platform and the path to the newly compiled binaries:
gem install sqlite3 --platform=ruby -- --with-sqlite3-include=[path\to\sqlite3.h] --with-sqlite3-lib=[path\to\sqlite3.o]
For example:
gem install sqlite3 --platform=ruby -- --with-sqlite3-include=/c:/dev/sqlite3/ --with-sqlite3-lib=/c:/dev/sqlite3/.libs/
(from the paths given in step 4)
Check the Gemfile.lock of your rails app and make sure that it points to the correct sqlite3 version. Mine was "sqlite3 (1.3.7-x86-mingw32)" and manually changed it to "sqlite3 (1.3.7-x64-mingw32)". Removing the platform also works: "sqlite3 (1.3.7)".
This is an old thread, but still relevant.
For us it was as simple as editing the Gemfile and adding a specific version for sqlite.
gem 'sqlite3', '~> 1.3.13'
I was able to install sqlite3 with ruby2.0.0 on win XP32 with following command:
c:\>gem install sqlite3 --platform=ruby -- --with-sqlite3-dir=C:/distr/sqlite --with-sqlite3-include=C:/distr/sqlite
Folder C:/distr/sqlite contains following files
shell.c
sqlite3.c
sqlite3.h
sqlite3ext.h
sqlite3.def
sqlite3.dll
So, basically I've extract sqlite-amalgamation-3071602.zip and sqlite-dll-win32-x86-3071602.zip to C:/distr/sqlite.
HEADS UP
You still need to put copy of sqlite3.dll and sqlite3.def somewhere to PATH. IMHO it's best to keep sqlite3 binaries in ruby's bin folder.
#!/usr/bin/env sh
mkdir c:/sqlite3x86
wget -P c:/sqlite3x86 http://packages.openknapsack.org/sqlite/sqlite-3.7.15.2-x86-windows.tar.lzma
cd c:/sqlite3x86
bsdtar --lzma -xf c:/sqlite3x86/sqlite-3.7.15.2-x86-windows.tar.lzma
gem install sqlite3 --platform=ruby -- --with-opt-dir=c:/sqlite3x86
cd c:/
rm -rf c:/sqlite3x86
For windows,
go to C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sqlite3-1.3.13-x64-mingw32/lib/sqlite3.rb
and make sure
require "sqlite3" instead of native
Get the fat binary from here
https://ci.appveyor.com/project/MSP-Greg/sqlite3-ruby/build/3/job/hhk6ie8gdo545svr/artifacts
and
gem install c:\path\to\downloaded_gem.gem
You should follow this procedure:
gem install bundler
(add in Gem file_)
gem 'sqlite3', ' < 1.4'(add in Gem file_)
then run:
install bundler
I figured I'd put in an answer -- from the comments, for posterity's sake. The issue seemed to be that I grabbed a new version of Ruby/Rails (for Windows) that was not compatible "yet" with SQLite3.
I downgraded to 1.9.x and was able to things running.
The easiest way to get set up for Ruby on Rails on a Windows machine is by using the RailsInstaller, which automatically installs and configures sqlite3 for you. One step.
http://railsinstaller.org/en

rails offline installation in windows

I want to install ruby on rails in offline mode (i.e. without internet connection). So I downloaded railsinstaller-3.2.0.exe from http://railsinstaller.org/en and installed it. By the end, I had ruby installed but in order to have rails installed I ran
gem install rails
and faced these errors: (meaning command needs internet connection)
ERROR: Loading command: install (ArgumentError)
unknown encoding name - CP720
ERROR: While executing gem ... (NoMethodError)
undefined method 'invoke_with_build_args' for nil:NilClass
I mean is there any solution like downloading gems with another computer connected to internet and then copying files in the proper location in the installed directory of gems.
Please help me if you have any idea.
As said in a comment, it's a gem (lib) dependency issue.
You might want to look into installing the bundler gem library to manage dependencies for you, with bundler you would just have to run, bundle install and it would download all the required gems for you including any gem dependencies.
You can install bundler simply, just run
gem install bundler
Then in your rails project directory, just run bundle install.
Often to run a project (like rails for example) you might have to start it with
bundle exec rails start
To install Gem's on a non-internet connect computer you might want to refer to this answer on just that problem.
This is the website where you can find all available ruby gems. Ruby
gems download. Find the one you are interested and download it.
Then move the gem in a directory of your choice and cd into that from
the command prompt. I am using C:/ruby193/bin/pony-1.4.gem
Let's say that the gem we are interested in is the pony gem (smtp
email).
Just type gem install pony-1.4.gem
and you should get it installed manually unless you have a restricted
acc with not adequate administrative privileges.
You can also refer to the official documentation on the matter.

Rails mysql2 installation on windows

Hello everyone I am new to rails I am following lynda tutorial and I am trying to install mysql2 but the error is showing I have look on various page of stack overflow but was not able to resolve it.My Error is
ERROR: Could not find a valid gem 'mysql2' (>= 0), here is why:
Unable to download data from https://rubygems.org/ - no such name (https://api.rubygems.org/latest_specs.4.8.gz)
On Windows, you need to use the following:
Download C-Connector & unzip to a non-spaced path on your system
Install the gem referencing the new path:
gem install mysql2 --platform=ruby -- --with-mysql-dir="C:/path/to/your/c-connector/install/no/spaces"
This should install the gem, allowing you to proceed with your other installation.
--
The reason this has to be done on Windows is due to the fact that the mysql2 gem requires an external set of dependencies (the c-connector plugin), which Windows does not have installed by default.
Linux users can use apt-get, and Mac users brew to get the dependencies; Windows users have to download it themselves.
If you follow the steps above, you should get the mysql2 gem installed.
I think there is some typos in your gemfile, Check if you have type correct version mentioned in the tutorial. mysql gem should look like below.
gem 'mysql2', '~> 0.3.11'

How do I install sqlite3 for Ruby on Windows?

Being really new to Ruby/Rails, and after attempting to resolve the issue myself this weekend I'm making an attempt to seek advice here.
I have a complete Ruby/Apache/Passenger setup done on FreeBSD, and I'm trying to accomplish the task of using Windows as a Ruby development environment.
So far:
Ruby is installed, v2.0.0p0 (2013-02-24) [x64-ming32]
Rails is installed, v.3.2.12
I have the Ruby dev kit installed and registered.
I have the sqlite3 dll/exe copied to the Ruby "bin" folder (which is also in my path using the "Start Command Prompt with Ruby" console.)
I can start a rails server successfully, and continuing with the http://guides.rubyonrails.org/getting_started.html tutorial to 3.3.
">rake db:create" tells me:
Please install the sqlite3 adapter: gem install activerecord-sqlite3-adapter (
sqlite3 is not part of the bundle. Add it to Gemfile.)
which I have no "understanding" of. Trying to install activerecord-sqlite3-adapter gives me a "Could not find a valid gem..."
">gem install sqlite3" returns:
Building native extensions. This could take a while...
ERROR: Error installing sqlite3:
ERROR: Failed to build gem native extension.
D:/Development/Ruby200-x64/bin/ruby.exe extconf.rb
checking for sqlite3.h... *** extconf.rb failed ***
Right now I'm stuck at the point where I don't even know what state my Ruby on Windows installation is in. I'm trying to follow the main Rails tutorial and it doesn't specify any of these issues (probably because Ruby on Windows seems to be a natural pain for a lot of people.)
What am I missing?!? I'm just trying to install sqlite3 for Ruby on Windows, seems simple right?
If I do ">rais db" the SQLite shell is presented:
SQLite version 3.7.15.2 2013-01-09 11:53:05
Similar questions with steps that do not resolve my issue:
Installing SQLite 3.6 On Windows 7
Even though the question has been answered, I want to post my research to help others. I found a lot of information online, but being a Ruby newbie I had a tough time following all. The basic answer comes from the following post https://github.com/luislavena/sqlite3-ruby/issues/82 with instructions by "paulwis" on how to properly install sqlite3 for ruby 2.0.0-p0 and some comments on https://github.com/rails/rails/issues/10150 . So here it is:
Install the Ruby Devkit for your setup (DevKit-mingw64-64-4.7.2-20130224-1432-sfx.exe for me since I use a x64 machine)
Download and extract the autoconf package from Sqlite.org
Run msys.bat (it is inside the ruby devkit root folder)
cd into the path where you downloaded the sqlite source (for example: "cd /c/dev/sqlite3" for path "c:\dev\sqlite3" if you are new to MSYS/MINGW32)
Run "./configure"
Run "make"
Run "make install"
Get the sqlite3 gem again, this time specifying the platform and the path to the newly compiled binaries:
gem install sqlite3 --platform=ruby -- --with-sqlite3-include=[path\to\sqlite3.h] --with-sqlite3-lib=[path\to\sqlite3.o]
For example:
gem install sqlite3 --platform=ruby -- --with-sqlite3-include=/c:/dev/sqlite3/ --with-sqlite3-lib=/c:/dev/sqlite3/.libs/
(from the paths given in step 4)
Check the Gemfile.lock of your rails app and make sure that it points to the correct sqlite3 version. Mine was "sqlite3 (1.3.7-x86-mingw32)" and manually changed it to "sqlite3 (1.3.7-x64-mingw32)". Removing the platform also works: "sqlite3 (1.3.7)".
This is an old thread, but still relevant.
For us it was as simple as editing the Gemfile and adding a specific version for sqlite.
gem 'sqlite3', '~> 1.3.13'
I was able to install sqlite3 with ruby2.0.0 on win XP32 with following command:
c:\>gem install sqlite3 --platform=ruby -- --with-sqlite3-dir=C:/distr/sqlite --with-sqlite3-include=C:/distr/sqlite
Folder C:/distr/sqlite contains following files
shell.c
sqlite3.c
sqlite3.h
sqlite3ext.h
sqlite3.def
sqlite3.dll
So, basically I've extract sqlite-amalgamation-3071602.zip and sqlite-dll-win32-x86-3071602.zip to C:/distr/sqlite.
HEADS UP
You still need to put copy of sqlite3.dll and sqlite3.def somewhere to PATH. IMHO it's best to keep sqlite3 binaries in ruby's bin folder.
#!/usr/bin/env sh
mkdir c:/sqlite3x86
wget -P c:/sqlite3x86 http://packages.openknapsack.org/sqlite/sqlite-3.7.15.2-x86-windows.tar.lzma
cd c:/sqlite3x86
bsdtar --lzma -xf c:/sqlite3x86/sqlite-3.7.15.2-x86-windows.tar.lzma
gem install sqlite3 --platform=ruby -- --with-opt-dir=c:/sqlite3x86
cd c:/
rm -rf c:/sqlite3x86
For windows,
go to C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sqlite3-1.3.13-x64-mingw32/lib/sqlite3.rb
and make sure
require "sqlite3" instead of native
Get the fat binary from here
https://ci.appveyor.com/project/MSP-Greg/sqlite3-ruby/build/3/job/hhk6ie8gdo545svr/artifacts
and
gem install c:\path\to\downloaded_gem.gem
You should follow this procedure:
gem install bundler
(add in Gem file_)
gem 'sqlite3', ' < 1.4'(add in Gem file_)
then run:
install bundler
I figured I'd put in an answer -- from the comments, for posterity's sake. The issue seemed to be that I grabbed a new version of Ruby/Rails (for Windows) that was not compatible "yet" with SQLite3.
I downgraded to 1.9.x and was able to things running.
The easiest way to get set up for Ruby on Rails on a Windows machine is by using the RailsInstaller, which automatically installs and configures sqlite3 for you. One step.
http://railsinstaller.org/en

Snow Leopard rubygems mysql2 and MAMP configuration for ruby on rails issue

This is my config:
rails 2.3.5
ruby 1.8.7
gem 1.8.11
mamp 2.0.3 (which uses Mysql 5.5)
When creating a new rails project with mysql as the database, I get an error:
An error occured while installing mysql2 (0.3.7), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.7'` succeeds before bundling.
I believe this is because gems can't find the MAMP mysql files. So a tutorial says I should download the MAMP libraries and compile it without server so I can then point the gem to those files. The problem is that all tutorials use ./configure which no longer works for Mysql 5.5, instead you have to use cmake. This tutorial: http://blog.mirotin.net/35/mamp-1-9-5-mysql-5-5-9-and-ruby-mysql2 mentions a way to do it using cmake, but this command fails for me:
sudo port install cmake
can't find command port. So I tried with homebrew sudo brew install cmake which gives:
Cowardly refusing to `sudo brew install'
So... What are my options? Rails and rubygems all seem to work, it's just pointing it to the MAMP mysql libraries that I'm having a problem with, I'm very new to rails (started yesterday). Any help would be appreciated.
Thanks.
In the end, installing cmake without sudo (who would have thought?) did work:
brew install cmake
Then I followed the instructions on this page: http://blog.mirotin.net/35/mamp-1-9-5-mysql-5-5-9-and-ruby-mysql2
and everything seems to be working. Also for those of us new to ruby on rails, you might need to edit config/database.yml and add the socket directive, pointing to the MAMP socket:
socket: /Applications/MAMP/tmp/mysql/mysql.sock
Hope this helps someone else.
PS
I'll be sure to mark this as answered and give me lots of credit for it, thereby showing appreciation for myself so I can answer my future questions!

Resources