ruby on rails with multiple databases ( mongodb, mysql ) - mysql

I'm planning to use multiple databases (mongodb, mysql) for my project.
And I have no idea with it.
Is there anyone can tell me how to connect mongodb and mysql to rails?
or any references?
Thanks.
-I'm using Ruby 1.9.3 and Rails 3.2

You need to setup your rails project with both of the database connections.
Firstly for Mongo, you need to decide which driver wrapper (if you use one) are you going to use. The two common ones are MongoID & MongoMapper. Both do pretty much the same thing and make it easy to interact with Mongo in a similar fashion to ActiveRecord.
To install these you merely install the appropriate gem e.g. for mongomapper you need to run 'gem install mongomapper'
Follow these Railcasts for step by step instructions:
MongoMapper or
MongoID
Now for mysql, again there is a gem to install, 'gem install mysql', and then follow the instructions on the 'getting started' ruby on rails guide to configure your database files.
Remember for both mongo & mysql you will need to have them installed and running somewhere that it accessible from development environment

Related

connect Rails application to a MySQL server

I'm trying to install MySQL adapter to connect my Rails application to a MySQL server, but when I try the command:
gem install mysql2
it return this error message:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /var/lib/gems/1.9.1 directory.
How can I fix it?
Thanks,RC
You don't have write permissions into the /Library/Ruby/Gems/1.9 directory.
means exactly that, you don't have permission to write there.
That is the version of Ruby installed by Apple, for their own use. While it's OK to make minor modifications to that if you know what you're doing, because you are not sure about the permissions problem, I'd say it's not a good idea to continue along that track.
Instead, I'll strongly suggest you look into using either rbenv or RVM to manage a separate Ruby, installed into a sandbox in your home directory, that you can modify/fold/spindle/change without worrying about messing up the system Ruby.
Between the two, I use rbenv, though I used RVM a lot in the past. rbenv takes a more "hands-off" approach to managing your Ruby installation. RVM has a lot of features and is very powerful, but, as a result is more intrusive. In either case, READ the installation documentation for them a couple times before starting to install whichever you pick.

Which tool usually use Ruby on Rails developers to handle administration of MySQL

I have Ruby on Rails application which is using MySQL database. For now I'm using phpmyadmin. But it requires PHP and Apache to run. Which tool usually use Rails developers to handle administration of MySQL?
If you're looking for a GUI try Navicat.
To answer your question, my experience is that Rails developers tend to use the command line to create a mySQL user and ActiveRecord rake tasks for the rest: rake db:create, rake db:migrate etc.
I'm using a mix of the mysql client, the rails console and Sequel Pro that is free but only running on macosx (it's a great piece of software by the way)

Facing lot of problems while using ROR

I am new to Ruby on Rails. I have read many article regarding easy installing steps. I installed ruby on windows. After starting the server i got welcome message too. After that if i add a controller I got this message on browser.
And also when tried to do a rake db:migrate i get the error saying mysql gem is missing.
I have installed mysql 5.0. I tried updating gem using this command and got this error.
C:\Documents and Settings\dchannap\Desktop>gem install mysql
ERROR: http://rubygems.org/ does not appear to be a repository
ERROR: Could not find a valid gem 'mysql' (>= 0) in any repository
My gem version is 1.3.7. and ruby is 1.9.1.
Can anyone help me in this regard. I hav to do a project on ROR..
Its probably internet connection or server side problem.
Here is similair question
You'll find it much easier to get started using SQLite3. Why not go with the flow for now? When you need to go more advanced you'll have much more experience with Ruby and Rails and Gems and you'll find it much easier to get sorted.
Are you behind a proxy? In that case you will have to specify it. E.g.
gem install --http-proxy http://your-proxy-address:8080 mysql
Thanks for all the replies.. I learnt Rails on Windows will face problems. And just tried with Instant rails. I faced no problems at all. I am able run small applicatins now.

Incompatibily between ruby and mysql gem

When trying to install the mysql gem from cPanel on my website, I get an error saying that the gem requires Ruby >= 1.8.6.
This is a shared server and the version of Ruby is 1.8.5 and can't be upgraded.
I do not have shell access and it seems the only way for me to install a gem is through the list of gems within cPanel.
How can I get mysql for my website?
You can try to install an older gem. 2.7.5 seems to be the proper version.
Ruby 1.8.5 is pretty old and as far as I know hasn't been actively supported by Rails for a while. You really need 1.8.6 and preferably 1.8.7. If your host won't upgrade it may be time to look elsewhere. If you really have no other option, you should to what Yuval suggests and try installing an older version of the gem.
No one having answered how to install a gem without shell access, I'll assume it can't be done and so will accept my own answer.

Access error occured in Ruby 1.9 + MySQL

I can't connect mysql db with ruby1.9
OS -> Windows XP SP2
Ruby -> 1.9.1p0
dbi -> 0.4.2
dbd-mysql -> 0.4.3
MySQL API module for Ruby -> 2.7.3
DB(MySQL) -> 5.1.34-community
Because msvcrt-ruby18.dll was not found, I was not able to start this application.
What's wrong
One of the gems is looking for ruby 1.8.x probably the dbi or dbd gem. Try it with ruby 1.8.7
You might also consider the newer Ruby installer built with mingw. A tutorial on installing Ruby 1.9.1 with MySQL is available from The Ruby Installer Tutorials
One of the modules your application depends on was built for Ruby 1.8. The most likely culprit is the MySQL client binding, but it could be some other dependency being imported elsewhere in the code, as well.
Generally speaking, the support for Ruby 1.9 isn't yet all that good across most applications and 3rd-party libraries. Unless you have a very strong reason to use it, you'll probably have better luck sticking with the latest 1.8.X release.