OpenShift Rails QuickStart


  1. Create a Ruby 1.9 application
    rhc app create -a railsdemo -t ruby-1.9
    
  2. After running the command railsdemo folder will get created in your directory. Run the command shown below. This will generate rails code in the railsdemo folder.It will ask you whether you want to override, say yes.
    rails new railsdemo
    
  3. Next run commands shown below
    cd railsdemo
    bundle install
    rails generate controller home index
    rm public/index.html
    
  4. Add the following route to config/routes.rb:
    root :to => "home#index"
    
  5. Generate Post entity with fields as shown below
    rails generate scaffold Post name:string title:string content:text
    
  6. Add Database support by uncommenting following lines from .openshift/action_hooks/deploy script
    pushd ${OPENSHIFT_REPO_DIR} > /dev/null
    bundle exec rake db:migrate RAILS_ENV="production"
    popd > /dev/null
    
  7. Add mysql cartridge
    rhc cartridge add -a railsdemo -c mysql-5.1
    
  8. Update config/database.yml
    production:
      adapter: mysql2
      encoding: utf8
      database: <%=ENV['OPENSHIFT_APP_NAME']%>
      pool: 5
      host: <%=ENV['OPENSHIFT_MYSQL_DB_HOST']%>
      port: <%=ENV['OPENSHIFT_MYSQL_DB_PORT']%>
      username: <%=ENV['OPENSHIFT_MYSQL_DB_USERNAME']%>
      password: <%=ENV['OPENSHIFT_MYSQL_DB_PASSWORD']%>
      socket: <%=ENV['OPENSHIFT_MYSQL_DB_SOCKET']%>
    
  9. Add gem in Gemfile
    gem 'mysql2'
    
  10. Add, Commit, and Push the Code
    git add .
    git commit -a -m "Initial setup"
    git push
    
  11. Finally you can view the application running at http://railsdemo-domainname.rhcloud.com and you can create new posts at http://railsdemo-domainname.rhcloud.com/posts
About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s