Support Center

Deploy a New Rails App

Last Updated: Jun 01, 2015 01:08PM CDT

To set up a new Rails app on a shared ASO account:

  1. Create a new Rails app via SSH
    Note: if you don't have SSH access you need to fill out a support ticket with us to gain access.

  2. Move into your home directory (if you just logged in, you are already there):

    cd ~
    
    
  3. 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)
    
    
  4. 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
    
    
  5. 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 by 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.

  6. Put this as the entire contents of the file:

    RailsBaseURI /myapp
    
    
  7. 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
    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:

    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:

    rails generate controller User list


    The above code would create the controller for the User object and it will also create the needed code for the list view.

  8. 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
    
    
  9. Create app/views/user/list.rhtml to allow you to view the list action at http://www.example.com/myapp/user/list.

  10. Configure your database.yml for database connections (we are using MySQL in this example):

    ​vi config/database.yml
    
    development:
    adapter: mysql
    encoding: utf8
    database: databasename
    username: username
    password: password
    hostname: servername
    
    test:
    adapter: mysql
    encoding: utf8
    database: test_databasename
    username: username
    password: password
    hostname: servername
    
    production:
    adapter: mysql
    encoding: utf8
    database: prod_databasename
    username: username
    password: password
    hostname: servername
  11. Create your first model (this will also generate your migration file)

    script/generate model User
  12. Edit the migration for this mode

    vi db/migrate/migrationname.rb
    class CreateUsers < ActiveRecord::Migration
      def self.up
    	create_table "users", :force => true do |t|
    	  t.column :login,                     :string
    	  t.column :email,                     :string
    	  t.column :created_at,                :datetime
    	  t.column :updated_at,                :datetime
    	end
      end
    
      def self.down
    	drop_table "users"
      end
    end
    
    
  13. Attempt to migrate your code (create the tables in the database)

    rake db:migrate
     

  14. Create your first controller

    rails generate controller user

    You can also predefine the list action. This will create the necessary view as well:

    rails controller user list

    Set the user controller and list action as your default action by first removing public/index.html and then uncommenting the map.root line in routes.rb:

    vi config/routes.rb

    You can have the root of your site routed with 'map.root', just remember to delete 'public/index.html'

Install the default routes as the lowest priority: map.root :controller => "user", :action => "list

​See how all your routes lay out with 'rake routes'?

map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
b2e1da5554fae60a8baf40cecd3cb9f6@asmallorange.desk-mail.com
https://cdn.desk.com/
false
desk
Loading
seconds ago
a minute ago
minutes ago
an hour ago
hours ago
a day ago
days ago
about
false
Invalid characters found
/customer/en/portal/articles/autocomplete