Getting Started
Posted by Administrator on 24 December 2009 10:48 PM
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 http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html.

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 "Congratulations" page

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.

OR

Via SSH2 command line. Upload your local machine database dump to app's db folder then:

[~/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:

production:
   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.

5. Make sure .htaccess sends requests to dispatch.fcgi

In public_html/.htaccess, change from:

RewriteRule ^(.*)$ dispatch.cgi [QSA,L]

TO:

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/images
public/javascripts
public/styles
public/.htaccess (as above)
config/database.yml (as above)
config/environment.rb (as above)
routes.rb
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 config/ folder

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

Other Notes:

Make sure the permissions are correct.

cd into railsapp directory and do:

$chmod -R 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)
require 'fcgi'
to
require 'fcgi'
require 'rubygems'
require_gem 'fcgi'


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 a subdirectory
change:
RewriteRule ^(.*)$ dispatch.cgi?$1 [QSA,L]

to:

RewriteBase /applfolder
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.
Do this:

$killall -9 ruby

several times. It might take several browser refreshes for the change to take place.

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.)





(713 vote(s))
Helpful
Not helpful

Comments (0)
Post a new comment
 
 
Full Name:
Email:
Comments:
CAPTCHA Verification 
 
Please enter the text you see in the image into the textbox below (we use this to prevent automated submissions).