Getting Started with Ruby on Rails
Here are some
instructions to get started:
For new application:
One will need to do everything in shell (ssh2).
One can grab a Windows SSH2 client such as PuTTy at
When you are logged into SSH2, do this:
$ rails /home/USER/testapp
$ cd /home/USER/testapp/
$ ruby script/generate controller test
$ cd /home/USER/public_html
$ ln -s ../testapp/public rails
(replace USER with your username)
Then navigate to http://www.yourdomain.com/rails/ and you should see a
For existing application:
1. Login to Cpanel and setup your database(s)
Â Â a) Create your database(s) and user(s)
Â Â b) Attach the user to the database
Note that the database and user is prefixed with your account name (ie
smith_databasename, smith_username) which
is important for database.yml file.
2. Dump your local machine database into new database you just created
One can do this via PHPMyadmin in Cpanel.
Via SSH2 command line. Upload your local machine database dump to app's db
[~/app]# mysql --user=username --pass=password
smith_database < databasedump.sql
3. Login to SSH2 and generate Rails app
At the /home/username directory, type:
[~]# rails app_name
4. Edit environment.rb and database.yml files
The database.yml file should consist of:
Â Â adapter: mysql
Â Â database: [your_cpanel_username]_[your_database_name]
Â Â username: [your_cpanel_username]_[your_database_username]
Â Â password: your_password
(You can basically remove all the other stuff in this file as the above
is all that's required)
The environment.rb file consist of:
ENV['RAILS_ENV']Â ||= 'production'
and upload them to config directory.
Make sure .htaccess sends requests to dispatch.fcgi
In public_html/.htaccess, change from:
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
6. Upload only essential folders and files to online app
Move the files and folders:
whole app folders (controllers, models, helpers, views)
public/.htaccess (as above)
config/database.yml (as above)
config/environment.rb (as above)
also any libs, scripts, environments
7. Make your app's public folder the public_html
(so yourdomain.com loads up your app)
Set the root route in route.db to name of your
main controller such as:
map.connect '', :controller => "your_main_controller_name"
Then upload the routes.rb file into online
Delete the index.htm or index.html in the public_html directory.
Finally, create symlink so www directory is the app directory.
Type the following command in root directory (/home/username):
[~]# mv ~/public_html ~/public_html_backup
[~]# ln -s ~/yourapp/public ~/public_html
Make sure the permissions are correct.
cd into railsapp directory and do:
u+rwX,go-w public log
These public directory and dispatch.fcgi must not be world writable and the log
directory must be writable.
In public/dispatch.fcgi change (if necessary)
Edit your appâ€™s public/.htaccess and change/add the following lines to make sure
that the Rails app is using FastCGI and that it knows that the app is living in
RewriteRule ^(.*)$ dispatch.cgi?$1 [QSA,L]
RewriteRule ^(.*)$ dispatch.fcgi?$1 [QSA,L]
Make sure that dispatch.fcgi is executable:
$ chmod 755 public/dispatch.fcgi
Switch to production mode by uncommenting line 5 in railsapp/config/environment.rb:
ENV['RAILS_ENV'] ||= 'production'
You might want to leave it at "development" until you're finished with theming
and config as you'll be purging the cache.
Once that's done, you can revert it back to production.
Our servers are CaSeSenSiTiVE. If you require any files, make sure they are the
same case as the actual file.
ie: require 'MD5'
will not work, but require 'md5' will.
Rail apps in production mode do not reflect changes made after they start
running. So if you found a bug, fixed it and nothing appeared to happen
then this is probably because you haven't restarted your fcgi process.
$killall -9 ruby
several times. It might take several browser refreshes for the change to take
Check log/fastcgi.crash.log, log/development.log and log/production.log for
error messages. If you find the "wrong" log is being written to, change
environment.rb to change modes as described above. (If you're in production
mode, and want to switch to development mode, you'll have to kill the Rails
process via "kill -9 ruby" or similar first.)