Get Ruby On Rails Up and Running
We use Ruby with Passenger while cPanel uses Ruby with Mongrel, so the cPanel Ruby app is not available. Below are the steps you need to take to get Ruby On Rails up and running.
Note: you will need SSH access, which is by default enabled on your account, and an SSH client (like PuTTY or XShell, or Terminal if you're on a Mac).
To begin setting up Ruby On Rails:
Move into your home directory (if you just logged in, you are already there)
Setup the LANG environment variable so there's proper UTF-8 support:
cd ~ echo "export LANG=en_US.UTF-8" >> ~/.bashrc source ~/.bashrc
Create the directory that holds your Rails application:
Note: MyApp can be changed to whatever you would like, but whatever you choose needs to stay the same wherever you type MyApp.
rails new myapp rails new -h (to see all rails commands)
Link your Rails application into your web directory so that you may access the Rails application on your website:
cd public_html ln -s ../myapp/public myapp
Let the server know about your Rails application by opening up the file located at myapp/public/.htaccess:
Note: You can access this over FTP or using the nano or vi commands over SSH. This file shouldn't already exist in the system. If it does, you can empty it's contents.
Put this as the entire contents of the file:
PassengerRuby /usr/local/bin/ruby PassengerAppRoot /home/username/path/to/app
Replace 'username' with your cPanel username and include the path to your app. If, for instance, your app is named 'myapp' in your home folder and your username is 'example', it will look like '/home/example/myapp'.
Create your needed models, controllers, and views for your application
Note: models are the objects, which will usually be linked to a table in your database.
A model can be created used the following command:
cd ../myapp script/generate model User (deprecated) rails generate model User
Note: a controller is what moves data between the model (database) and your view.
A controller can be created using the following code:
script/generate controller User (deprecated) rails generate controller User
Note: the view is where you will control what the user sees.
The view can either be created manually or with help of the generator:
script/generate controller User list (deprecated) rails generate controller User list
The above code would create the controller for the User object and the needed code for the list view.
If you would like to manually create this, edit the User controller file, found at app/controllers/user_controller.rb, by entering the following code within the class (after class and before end):
def list end
Create app/views/user/list.rhtml which will allow you to view the list action at http://www.example.com/myapp/user/list (update "example.com" to your domain)
Hopefully this will provide a small amount of help for you to get the application up and running! See below for some helpful tips from a user...
Ignore the Ruby on Rails Config panel on cPanel! ASO does not use Mongrel or WEBrick, we use Passenger. Follow the instructions above and ignore the Ruby on Rails config panel.
If you are developing a Facebook app you will probably see a 405 error. I believe this is because Facebook is using IIS, which does not like a redirect to a URL that refers to the default page for that URL.
To get around this, add the following to your public/.htaccess:
RewriteRule ^/$ /my_default_controller [QSA]