Skip to content

Instantly share code, notes, and snippets.

View cody-code-wy's full-sized avatar

William Young cody-code-wy

View GitHub Profile
@cody-code-wy
cody-code-wy / semenhub_override.js
Last active December 19, 2017 21:58
Override semenhub.com tiles
$( function() {
$('img[alt="Whitetails"]').parent().attr('href','http://www.semenhub.com/Default.aspx?id=98359&Title=WhitetailHub');
$('img[alt="Goats"]').parent().attr('href','http://www.semenhub.com/Default.aspx?id=108098&Title=GoatHub');
$('img[alt="Wagyu"]').parent().attr('href','http://www.semenhub.com/Default.aspx?id=108101&Title=WagyuHub');
$('img[alt="Watusi"]').parent().attr('href','http://www.semenhub.com/Default.aspx?id=107829&Title=WatusiHu');
})
This is a test of a gisting application...
this is a test of a gisting application...

Rotten Mangoes

Let's get going on our second Rails app!

We're going to build a Rotten Tomatoes clone called Rotten Mangoes. This app will be our first dive into several crucial Rails concepts that will serve you well into the future:

  • associations
  • validations/errors
  • “business logic” (it's business time)
  • partials
  • helpers
/* Exercise 1 */
SELECT isbn
FROM publishers JOIN editions
ON editions.publisher_id = publishers.id
WHERE publishers.name = 'Random House';
/* Exercise 2 */
SELECT isbn, title
FROM publishers JOIN editions
ON editions.publisher_id = publishers.id JOIN books
ON editions.book_id = books.id
==== start log session ====
0.000024 function gitgutter#process_buffer[10]..gitgutter#diff#run_diff[73]..gitgutter#utility#system[1]:
0.000024 cd /Users/cody && (git ls-files --error-unmatch .vimrc && (git -c "diff.autorefreshindex=0" diff --no-ext-diff --no-color -U0 -- .vimrc | grep --color=never -e '^@@ ' || exit 0))
==== start log session ====
0.000042 function gitgutter#process_buffer[10]..gitgutter#diff#run_diff[73]..gitgutter#utility#system[1]:

The self keyword

Self in instance methods

Self referst to the instance of a class it is evoked from. Or in other words, it allows you to address methods on its own instance. This feature is not normally required in ruby. It is most usefull when a method's name is ambiguous between instance methods, and other methods that are in scope.

Defining class methods

Self can also be used to define class methods, for example

module Flight
def fly
puts "I'm a #{self.class.name}, I'm flying!"
end
end
class Animal
@name = "Animal"
@states = {
OR: {name:'Oregon',city:["Portland","Bend"],tax:1},
FL: {name:'Florida',city:["Orlando","Miami"],tax:0.9},
CA: {name: 'California',city:["Los Angeles"],tax:0.2},
NY: {name:'New York',city:["New York","Albany"],tax:0},
MI: {name:'Michigan',city:["Ann Arbor","Jackson"],tax:0.4}
}
@states[:TX] = {name:"Texas",city:["Dallas","Huston","Austen"],tax:8}
@states[:WA] = {name:"Washington",city:["Spokan","Seattle"],tax:0.1}