Run the following command from anywhere in Terminal:
echo PS1=\"\\w $ \" >> ~/.bash_profileHere's a general workflow that you ought to think about while doing homework:
Ruby is a wonderfully simple language, and Rails is an astonishingly powerful framework. Unfortunately, installing them can sometimes be the hardest part of learning to code.
In this guide I will lay out the least error-prone method of installing that we've found. Hopefully you will have no issues and it will be smooth sailing.
In case you do run into an error, first try restarting your computer and then re-try the last step that you got stuck on. If that doesn't work, we'll fix it together.
If you can't install Ruby on your laptop for some reason (for example, it belongs to your employer and you are not allowed to install things), skip to here.
We are going to be writing all of our code using the plain text editor Sublime Text 3. In this guide, you will customize your installation with shortcuts and other things in order to make your life easier.
What follows may seem opaque, but don't worry about it -- we just need to go through this process once, and then we'll be all set for the quarter. You aren't expected to understand exactly how it is all working right now.
Download Sublime Text 3 (not 2) for your platform of choice [here][1], and install it (locate and double-click the file you just downloaded).
| # The following line will pull Rails' enhancements of Ruby's Date class into | |
| # this script. | |
| # You will then be able to use methods like Date.today, which returns an object | |
| # representing today. | |
| # You can also do things like Date.parse("1809-02-12") and it will return an | |
| # object representing that date. | |
| # You can then subtract one from the other to find the number of days between. | |
| require 'active_support/core_ext/date/calculations' | |
| class Person < Primate |
| module ApplicationHelper | |
| def list_tag(name, *args) | |
| options = args.extract_options!.merge(name: name, list: name) | |
| input_tag = tag :input, options | |
| datalist_tag = content_tag :datalist, nil, id: name do | |
| args[0].collect do |value| | |
| tag :option, value: value | |
| end.join.html_safe | |
| end |
| /* http://meyerweb.com/eric/tools/css/reset/ | |
| v2.0 | 20110126 | |
| License: none (public domain) | |
| */ | |
| html, body, div, span, applet, object, iframe, | |
| h1, h2, h3, h4, h5, h6, p, blockquote, pre, | |
| a, abbr, acronym, address, big, cite, code, | |
| del, dfn, em, img, ins, kbd, q, s, samp, | |
| small, strike, strong, sub, sup, tt, var, |
| require 'open-uri' | |
| require 'json' | |
| require './student.rb' | |
| url = "http://yearbook-api.herokuapp.com/2013/Spring/36.json" | |
| raw_response_string = open(url).read | |
| ruby_response_object = JSON.parse(raw_response_string) | |
| list_from_api = ruby_response_object["students"] |
| class Student | |
| attr_accessor :name, :photo_url, :section, :twitter | |
| def introduce | |
| return " <li> | |
| <img src='#{self.photo_url}'> | |
| <h3><a href='https://twitter.com/#{self.twitter}'>#{self.name}</a></h3> | |
| </li>" | |
| end | |
| end |
| require 'open-uri' | |
| require 'json' | |
| your_access_token = "put your access token from the Graph API Explorer here" | |
| url = "https://graph.facebook.com/me/home?fields=from,picture,link,source,name,description,type&access_token=#{your_access_token}" | |
| result = JSON.parse(open(url).read) | |
| posts = result["data"] |