Skip to content

Instantly share code, notes, and snippets.

@zeke
Last active October 9, 2015 13:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeke/3e1d162f009a2387f56a to your computer and use it in GitHub Desktop.
Save zeke/3e1d162f009a2387f56a to your computer and use it in GitHub Desktop.
puts "hello world"

Interactive ruby:

irb

Type exit to get out.

From the bash command prompt, type clear to clear the screen.

Let's make some people!

rails g scaffold person first_name:string last_name:string spirit_animal:string favorite_color:string favorite_number:float zipcode:integer --pretend
rake db:migrate

To list all available rake tasks:

rake -T
rake -T | grep db

People are live at https://tts-rails2-zeke-1.c9.io/people

Add this to config/routes.rb:

root to: 'people#index'

Working on a stylesheet:

$table-heading-color: #999;

body {
  font-family: "helvetica neue", helvetica, arial;
}

th {
  font-weight: normal;
  color: $table-heading-color;
  text-align: left;
}

table {
  border-collapse: collapse;
  width: 100%;
}

th, td {
  padding: 5px;
}

tr:nth-child(even) {
  background: #EEE;
}

.color-box {
  width:20px;
  height:20px;    
}

HTML for the color-box to be added to app/views/people/show.html.erb:

<div class="color-box" style="background:<%= @person.favorite_color %>;"></div>

HTML for making each person's name a link to their page:

<td>
  <%= link_to person.first_name, person %> 
</td>

Add a first name method to app/models/person.rb:

class Person < ActiveRecord::Base
    
    def full_name
       [first_name, last_name].join(" ")
    end
    
end

Futility! Open up irb in your shell:

color = "red"
phrase = "My favorite color is #{color}"  
phrase.upcase.reverse.split(" ").join(" ").reverse.downcase

State of the person model:

class Person < ActiveRecord::Base
    
    def full_name
       [first_name, last_name].join(" ")
    end
    
    def cleaned_up_favorite_color
        favorite_color.gsub(" ", "") 
    end
    
    def spirit_animal_wikipedia_url
      "https://en.wikipedia.org/wiki/#{spirit_animal}"
    end
    
    def spirit_animal_lucky_url
      "http://www.google.com/search?&sourceid=navclient&btnI=I&q=#{spirit_animal}"    
    end
    
    
    
end

Go to the shell and type:

rails console
@jbnv
Copy link

jbnv commented Oct 8, 2015

The stylesheets are located at app/assets/stylesheets.

Copy link

ghost commented Oct 9, 2015

Thanks for these notes. Class was very enjoyable today.

@cautin
Copy link

cautin commented Oct 9, 2015

Thanks, Zeke - this was a great class! Cliff

@cgaines5
Copy link

cgaines5 commented Oct 9, 2015

Awesome class, Zeke! Glad I went!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment