HW2: Ruby advance and Rails intro

作者: 云中布衣   分类:  数据比赛    热度: (1290℃)   时间: 2015-10-14 22:30   标签: #作业  #ruby  #rails  #高级软件工程    

This homework is to get you more familiar with features of ruby and have a sense of creating apps in rails.  Considering the workload of this homework, the deadline is a bit flexible. Please complete the second section (deploy rottenpotatoes) before next lecture. Please complete as much as you can the first section (ruby calisthenics) in the next two weeks. It is very important to try test-driven development using RSpec.

(section 2)Rails Intro

Get RottenPotatoes running locally

The actual RottenPotatoes starter app you will use is in repo:


.Clone onto your development computer:

git clone


If password is needed, uses 20150917

Whenever you start working on a Rails project, the first thing you should do is to run Bundler, to make sure all the app's gems are installed. Switch to the app's root directory (presumably rails-intro) and run bundle install --without production(you only need to specify--without production the first time, as this setting will be remembered on future runs of Bundler for this project).

If there is an error information on installing gems, edit source to 'http://ruby.taobao.org' in Gemfile.

Finally, get the local database created:

rake db:migrate

  • Self-check: how does Rails decide where and how to create the development database? (Hint: check the db subdirectory)

This creates a local development database and runs the migrations to create the app's schema. It also creates the file db/schema.rb to reflect the latest database schema. You should place this file under version control.

  • Self-check: what tables got created by the migrations?

...And insert "seed data" into the database--initial data items that the app needs to run:

rake db:seed

  • Self-check: what seed data was inserted and where was it specified? (Hint:rake -T db:seed explains the seed task;rake -Texplains other available Rake tasks)

At this point you should be able to run the app locally (rails server) and navigating tohttp://localhost:3000/moviesin your browser.

Deploy to Heroku

If you have deployed to Heroku before, just create a new app container with heroku create. If this is your first time deploying to Heroku, you will need to do two things. First, sign up for a free Heroku account. Then set up ssh keys to securely communicate with Heroku for app deployments. The three basic commands you need are the following, but see the Heroku page for more details.

ssh-keygen -t rsa
heroku login
heroku keys:add

Once your keys are set up (a one-time process), you should be able to create an "app container" on Heroku into which you'll deploy RottenPotatoes:

heroku create

Heroku will assign your app a whimsical name such asluminous-coconut-237; once your app is deployed, you would access it athttp://luminous-coconut-237.herokuapp.com. You can login to the Heroku website if you want to change the name of your app.

Finally, we deploy our app to Heroku:

git push heroku master

(It is normal to see the following warning the first time---answer "yes", and in the future you shouldn't see it any more:)

The authenticity of host 'heroku.com (' can't be established.
RSA key fingerprint is 8b:48:5e:67:0e:c9:16:47:32:f2:87:0c:1f:c8:60:ad.
Are you sure you want to continue connecting (yes/no)? 
Please type 'yes' or 'no':

Is the app running on Heroku? No, because just as we ran rake db:setup to do first-time database creation locally, we must also cause a database to be created on the Heroku side:

heroku run rake db:setup

Now you should be able to navigate to your app's URL. heroku open opens your browser to that URL in case you forgot it.

Once you're confident the functionality works correctly on Heroku, submit the URI of your deployed Heroku app in a text file with no other contents.

Please be careful to use http and not https, that is, submit http://your-app.herokuapp.com and NOT https://your-app.herokuapp.com.



© 云中布衣 2015 | Driven by EMLOG  | SiteMap | RunTime: 9.50ms&RSS  |   | 回到顶部

文章数量【230】 评论数量【156】 稳定运行【1030天】

Visitor IP Address【】