Tuesday, January 12, 2016

Chapter 1

  • Using a cloud integrated development environment (cloud IDE) such as Cloud9 saves time by sidestepping multiple configuration and installation issues.
  • In Cloud9, Rails needs to be installed by the command "gem install rails"
  • Once Rails has been installed, you can use "rails new appname" to create a new app named appname.
  • In this case, one needs to edit the Gemfile and run "bundle install" to install some needed Gems that were not installed by default. (Even though bundle install was already run as part of the rails new command)
  • "rails server -b $IP -p $PORT" then creates a local web server.
  • One can then edit the controller in application_controller.rb to adjust what the program displays by default.
    • For example, once can define a function "hello" which renders text "Hello, World!"
    • Thereafter, go to config/routes.rb and add "root application#hello" to ensure that the function "hello" within the "application_controller.rb" file is performed when there is a request to the root route (or root URL). Notice that application is the controller name, and hello is the function.
  • One can then use Git for version control.
    • git init
    • git add -A (add new files)
    • git commit -m "I made some edits" (commits changes)
      • When no new files are created, one may replace the last two commands with git commit -a -m "I made some edits"
  • One can then set up Bitbucket and copy the SSH key from Cloud9 to Bitbucket
    • git remote add origin git@bitbucket.org:<username>/hello_app.git
    • git push -u origin --all
  • Don't forget to set up branches when experimenting.
    • git checkout -b modify-readme (creates branch called modify-readme)
    • (make edits)
    • git checkout master
    • git merge modify-readme
    • git branch -d modify-readme (deletes the branch; use only after you've tidied up)
    • git push (pushes to Bitbucket)
  • Since Heroku uses PostgreSQL, we need to add the pg gem into the production environment to allow Rails to talk to Postgres. We also need rails_12factor to serve up static images and stylesheets.
  • Then use "heroku create" to create a heroku app, as well as "git push heroku master" to push the master branch up to heroku.
  • Use the "heroku rename" to rename the website if you want a prettier name.

No comments:

Post a Comment