Trouble Setting Up Ruby On Rails - mysql

I'm attempting to start learning Ruby on Rails via a YouTube tutorial series(https://www.youtube.com/watch?v=GY7Ps8fqGdc), but seem to be struggling getting everything properly installed and set up to do so. The tutorial requires MySQL with MySQL Workbench and Ruby on Rails. I've gotten several errors in the first few steps and taken some steps to try to resolve them, here's basically where I've gotten.
Installed the most recent version of MySQL and Ruby on Rails. I ran the rails new [name] -d mysql command without issue and it ran to completion. I then navigated to the newly created project folder and ran the bundle install at which point I was given the following error:
Gem::InstallError: nio4r requires Ruby version >= 2.3.
An error occurred while installing nio4r (2.5.2), and Bundler cannot continue.
Make sure that `gem install nio4r -v '2.5.2'` succeeds before bundling.
At this point I installed version 2.6 of Ruby on the machine, which did not seem to yield any improvements. Basically I think I'm overcomplicating all of this and want to know if anyone has an easy solution to install all the tools required for working in Ruby on Rails.
Thanks

First thing first, you're following a 5 yr old tutorial on youtube.
I would advise to always follow the newer ones even though some of the old ones might still work and the reason is simple; recent tutorials will probably work off the bat.
Now, judging by the video you shared, I can see that you should've installed RVM at some point. Official RVM website
In your terminal run ruby -v and check if you're actually using the Ruby version you just downloaded. To change the ruby version while using rvm you should use in your terminal:
$ rvm list
To check on your available ruby versions installed and then
$ rvm use <version>
This will switch your ruby version to the one you want. ( If you already installed it of course. ) and then try bundle install again.
Since you were asking for an easier solution I'd say to try following Rails official getting started guide. This guide installs the minimum amount of gems which will help you avoid all these version issues and even though it uses sqlite instead of mysql, later on you will be able to switch to mysql if you want with a better understanding of it.

Related

How to get NetBeans 7.4, Ruby and MySQL to play together (on Windows)

The tags say it all, really. This is a project that used to work on earlier versions, but not now. If you know the answer, just stop reading and tell me how.
An existing project is working fine on older releases of NetBeans and MySQL. I am just trying to get it working on the latest release of everything. Nothing fancy. Just plain vanilla Ruby on Rails on Windows/MySQL.
Clean install of Netbeans 7.4. No problems.
Clean full install of MySQL 5.5. No problems. Includes Java connector.
Clean install of ruby and rails from community: http://plugins.netbeans.org/plugin/38549. No problems.
Everything is working just fine.
Webrick starts and runs. Absolutely no surprises to this point.
I tried to gem install MySQL: it fails, but it is not unexpected. I have no interest in pursuing that line. Ditto for MySQL 2. It's always hard building native libraries on Windows.
I tried to gem install all/any of the following:
* activerecord-jdbc-adapter
* activerecord-jdbcmysql-adapter
* jdbc-mysql
They install just fine, but the end point is always the same:
cannot load com.mysql.jdbc.Driver.
I think I know what this means, but I have no idea how to fix it. Is it a classpath problem? Is it a bug? Is it an incompatibility just about to be fixed? Is it because I'm using Windows? Who knows? I can't think of anything else to try, and the forums are full of these errors with no solutions that seem to fit my problem.
I am not sure, but maybe the blog post Installing MySQL on Windows 7 x64 and using Ruby with it will help.

Stuff not included in RailsReady?

I tried to install RoR on Ubuntu 12.0.4 using RailsReady(https://github.com/joshfng/railsready). Afterwards I restarted my computer and while typing ruby -v works, typing rails -v returns unrecognized, as does mysql in the terminal. What do I have to do to be able to launch rails and mysql? Do I have to install them individually using sudo even though I've already installed RailsReady? Thanks.
A quick glance at the README and the script itself shows that it gets you ready to install Rails by installing typical packages needed in order to create a Rails-based development environment, and then attempts to install it.
Per #madth3's comment below, lines 176 to 182 of railsready.sh does attempt to install Rails, so look for any error messages when you run that script.
MySQL appears to require separate installation using standard methods appropriate for your system.

Ruby on rails undefined method `where' for #<Class:0x10377d590>

I am trying to migrate from windows 7 to mac osx .
I have installed the following
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
mysql Ver 14.14 Distrib 5.1.56, for apple-darwin10.3.0 (i386) using
readline 5.1
After a lot of pain I installed my sql gem by :
sudo env ARCHFLAGS="-arch x86_64" gem install --no-rdoc --no-ri mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
But still when I run my project in netbeans I get the following error
[4;36;1mUser Columns (31.5ms)[0m
[0;1mSHOW FIELDS FROM users[0m
[4;35;1mSQL (1.2ms)[0m [0mSHOW
TABLES[0m /!\ FAILSAFE /!\ Wed May
04 09:53:16 +0530 2011 Status: 500
Internal Server Error undefined
method `where' for
Can anyone tell me what am I doing wrong ?
The database migrations are working perfectly.
You stopped copying the stack trace right at the point where it was about to tell you where the error occurs. Look down the stack trace for the first mention of any code from your app (as opposed to the gems or the vendor folder) and it should point you to the problem line.
It's unfortunate that you've having such a time installing the MySQL gem, but this can be complicated if you're loading it on a from-scratch machine that's missing the development headers, something required to compile the extension, and your path does not include /usr/local/mysql/bin which is common.
You can fix that by creating a file /etc/paths.d/mysql with the following:
/usr/local/mysql/bin
Generally you should just have to list mysql in your Gemfile after that, and it should install conventionally with bundle install.
As for the error, it looks like something deeper in your application that's blowing a gasket. When you say "run your project in netbeans," but do you mean run unit tests? It looks like you're calling where on something that doesn't support it.
This looks like an application error. The server is bailing with a 500 when it fails to evaluate the method 'where', somewhere likely in your code.
Modern Mac operating systems (forget which was the first) come with ruby and rails pre-installed - not sure if this is related to your setup.
What happens when you run
rails server
from the console (from within the directory of the app) ?
where is a ActiveRecord 3 AREL class method used for conditions.
First things first, do you have XCode installed? thats a prerequisite to installing any native gems. You can download XCode 3 from the apple site or buy XCode 4 from the app store.
More of the stack trace is required.
Ideally though, once you have installed XCode, you should take a look at https://rvm.io - it's the preferred way for managing rubies on Unixy systems.
Thanks guys.. I finally found the error was with the authlogic gem
I had installed 3.0.2
and the application requires an older version 2.x

Installing Rails, MySQL, etc. everything goes wrong

I've been struggling with this for a few hours. Everything just stopped working and I can't get it to work anymore. I'm a noob at Ruby, Ruby on Rails and the Terminal in general. This is really frustrating me so I just try to describe my problem as detailed as possible hoping someone can give me a solution.
I'm on Mac OS X Snow Leopard. I couldn't get Rails working at all just now: Could not find gem 'rails' headaches
But after some tries of reinstalling it, it suddenly worked again. But now I just can't get MySQL to work, and it sometimes even breaks the Rails installation again.
This is what I do:
sudo gem uninstall rails
sudo gem uninstall mysql
sudo gem uninstall mysql2
After these commands, I check the installed gems with gem list. No MySQL gem is listed anymore, but I can still see rails (2.3.5, 2.2.2, 1.2.6)
. Is this normal? Does this mean I have 3 Rails installations? It doesn't make sense to me. Anyway, then I do this:
sudo gem clean
Which fails completely. I get a bunch of errors like this:
Attempting to uninstall fcgi-0.8.7
Unable to uninstall fcgi-0.8.7:
Gem::InstallError: cannot uninstall, check gem list -d fcgi
It doesn't uninstall anything. At this point, I try to install everything again. I start with:
sudo gem install rails
Which succeeds (I think):
Successfully installed rails-3.0.3
Successfully installed builder-2.1.2
2 gems installed
Installing ri documentation for rails-3.0.3...
File not found: lib
Then, I update RubyGems:
sudo gem update --system
sudo gem install rubygems-update
sudo update_rubygems
Then it says I have 1.3.7 installed, so it succeeded, I think. So now I proceed with installing MySQL. I already got MySQL 5.5.8 installed on my machine. I did some research about installing MySQL on Snow Leopard, and it seems I have to use this command:
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
I get a bunch of errors like this:
No definition for time_set_neg
No definition for time_set_second_part
No definition for time_equal
No definition for error_errno
At this point, I assume I got both Rails and the MySQL gem installed, so I try to start a new project.
rails new user_group -d mysql
It works! Rails is installed correctly. Now, I try generating a model.
cd user_group
rails generate model User
It fails with this error:
Could not find gem 'mysql2 (>= 0, runtime)' in any of the gem sources listed in your Gemfile.
Try running bundle install.
So I try running bundle install. It installs a lot of gems. Then I try to generate my model again. I get this error:
Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle: dlopen(/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.16.dylib (LoadError)
Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
Reason: image not found - /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
This is as far as I can get. What should I do? And why should this be so hard...
Snow Leopard supplies Ruby 1.8.7. Ruby 1.8.7 doesn't automatically add the require 'rubygems' command to a Ruby script, like 1.9.2 will, so in general you need to add that to your script. That fixes the problems with Ruby not finding the gems called by your code in a lot of cases. Rails is a different animal, but the version with 1.8.7 is well documented so you should have found a fix pretty quickly.
The Ruby supplied by Snow Leopard is really for its own use. Users can piggyback on that, but it's installed by Apple because they have applications that use it. Use locate podcast | grep rb$ to see. Similarly, Perl and Python in Snow Leopard are used to support code Apple has installed so messing with them is not a good idea. Changing the built-in Ruby, Perl or Python usually won't cause the system to explode in flames, but it can cause irritating and unexplained problems farther down the road when system maintenance routines stop working.
By using sudo to remove gems installed by Apple and add new ones, you've left your system Ruby in an unexpected state as far as Apple's apps are concerned. Rather than mess with Apple's Ruby, you should install a separate Ruby for your own use using Fink or MacPorts, or from source code, or by using RVM.
Personally, I use RVM because it creates a ~/.rvm sandbox in your home directory, and makes it easy to manage multiple versions of Ruby and gems. RVM requires you to install the XCode development library, which you can download from http://developer.apple.com/technologies/ after a free registration. XCode is also on your system DVD, but that version is reported to be buggy, so use the downloaded version.
Make sure to add the MySql gem to that projects gemfile with the following code:
gem 'mysql', '2.8.1'
Run a bundle install/update and try it. You told it to use MySQL and the gem might even be installed, but you aren't loading it.
Also, you're failing at a couple of points: notice the
File not found: lib
Then again, I could be completely wrong about this - it's my attempt at providing a clue for your troubleshooting.

Installing MYSQL and passenger gems, getting no definitions for documentation

I'm running Mac OSX 10.6.4 and setting up rails for the first time. I've been following a bunch of guides to get set up, specifically these two here and here. Also, I know this question has been asked before, but nothing has helped me and my circumstances are a bit different.
First, let me give you my setup.
I've installed Xcode, but I don't want to use the system ruby so, what I did was, I installed RVM and created two gemsets for different ruby versions (1.8.7#rails2.3.8 and 1.9.2#rails3), cause I also want to try rails 3.
I created a global gemset so that I could install passenger and mysql for 1.8.7 and not have to do it for each project. Then set the global gemset by rvm gemset use global
I had already installed MacPorts in a previous step, so what I've done is install mysql using this command sudo port install mysql5 mysql5-server.
Now I run gem install passenger and then passenger-install-apache2-module. This is where I ran into the first issue. Passenger installed fine, but I got "no definition" errors when it tried to install the documentation.
Finally, I want to install the mysql gem so I followed the steps here by adding rvm_archflags="-arch x86_64" to the ~/.rvmc file and then ran export ARCHFLAGS="-arch x86_64" ; gem install mysql -- --with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config Here is where I ran into the issue again. I got a "Successfully installed mysql-2.8.1" message, but all the documentation returned "no definition" errors!
So, why am I getting these errors when installing gems? What can I do to get them installed without errors and ensure future gem installations don't have this problem?
Note: I'm not using sudo because RVM tells you not to.
Here is a link to your problem. They are saying the same thing and the answer is that it's just noise. Obviously something is not right but there is not and should not be a problem. It's most likely that all is fine and documentation was not created, installed, or linked correctly.
http://www.sitepoint.com/forums/showthread.php?t=629077
A -- alone (as written in step 5) usually means to stop reading options. I expect that this is wrong and doesn't belong here or is incomplete (ie, should be --something).