RubyOnRails4Beginners
The intention of this page is to help the beginner programmer with installing and deploying a ruby on rails application on Ubuntu. This is intended for the community.
From the Ruby on Rails side, please see http://wiki.rubyonrails.org/rails/pages/RailsOnUbuntu and from the Ubuntu side, please see https://help.ubuntu.com/community/RubyOnRails.
The instructions basically follow this:
- Get Ruby and Rails working
- Get mySQL working
- Get Ruby tests passing
_1. Get Ruby and Rails working_
Suggest you use the RubyOnRails page for a reference. Because of the "contention" between gems and apt-get (synaptic manager), use gems installation from the source files for gems to avoid future problems. This is unlikely to be resolved anytime soon, but only applies to the gems. (not ruby and not mysql)
- ubuntu-machine$ rails myfirstproject
Once you have created your first project, a database.yml file will be created that will include the login credentials for your local instance of mysql. Edit that file to match the mysql credentials you offer below (i.e. user = mysr and password = 'poor-password'.
_2. Get mySQL working_
mySQL is not required for developing a Ruby On Rails web application, but a database is required for most web applications, and mySQL is the likely choice for most open source developers.
MySQL
- You will need to install mySQL. Use the synaptic package manager (System - Admin menu) and select only mysql-server.
- $sudo apt-get mysql-server
- Setup the databases -
While setting up mySQL on Ubuntu is fairly straightforward, troubleshooting issues is not.
* This involves using the mySQL interface, either command line or graphical. I prefer the command line. * First, look in Admin: Services to see if mySQL is starting up. * If not running, then open up a terminal window and type 'mysqld_safe --user=mysql &' * Assuming you have an instance of mySQL running on your machine, set up the database, then modify the /path-to-ruby-project/config/database.yml file to include the credentials you give it here.
- example: ubuntu-machine$ mysql -u root (no password initially)
mysql> create database myrailsproject_development;
mysql> grant all on myrailsproject_development.* to 'myusr'@'localhost' identified by 'poor-password'
When setting up mysql to work on Ubuntu, you may need to change the file permissions of the databases. The owner of a file (in this case a database) automatically has more rights. You can also change the rights for everyone by changing the overall rights. Those are the commands you see as chmod 777 (opens it wide open) and chmod 744 (open it up for execution). See FilePermissions for a more thorough explanation on files and permissions. Chgrp changes the group that owns the file or directory. Group rights are inherited by members.
If you get an error on the ruby statement:
$ Ruby db:migrate
"usr"@"localhost" does not have permissions,
- then you need to address this issue by changing the permission on the database and/or by owning the database with the usr.
The database will be created in the directory /var/lib/mysql
Try
- ubuntu-machine$ chown myusr /var/lib/mysql/myrailsproject_development
If you get an error that myusr doesn't exist, then you need to use the Admin menu and go to the Users and Groups utility and create that user (use the same case). Make that user a part of a user group, let say 'special-mysql-group'.
Then also try:
- ubuntu-machine$ chgrp special-mysql-group /var/lib/mysql/myrailsproject_development
and don't forget to do the same for the /myrailsproject_test database.
_3. Getting tests to pass_
Ruby On Rails is test-driven, so that when you run $ Rake, you are asking Ruby to compile the application into its "run-time" and run the battery of tests. I found that I could not get the tests to pass, even on a fresh install of ruby and with no content in my ruby application.
It is suggested that the /myrailsproject/tmp and /log directories could be the issue.
One way to solve this is to use: ubuntu-machine$ sudo chmod 744 -R path-to/myrailsproject
to make sure this is working: ubuntu-machine$ rake
Now that you have Rails working, you might wonder about deploying the application onto a hosted environment. Most books assume that you control the server and can configure it. There are a few options for running it at an ISP.
RubyOnRails4Beginners (last edited 2008-08-06 16:14:38 by localhost)