- Create a Ruby 1.9 application
rhc app create -a railsdemo -t ruby-1.9
- 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
- Next run commands shown below
cd railsdemo
bundle install
rails generate controller home index
rm public/index.html
- Add the following route to config/routes.rb:
root :to => "home#index"
- Generate Post entity with fields as shown below
rails generate scaffold Post name:string title:string content:text
- 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
- Add mysql cartridge
rhc cartridge add -a railsdemo -c mysql-5.1
- 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']%>
- Add gem in Gemfile
gem 'mysql2'
- Add, Commit, and Push the Code
git add .
git commit -a -m "Initial setup"
git push
- 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