From c8dfb4bc09454f878318ea20c37cac93eb7ec4c1 Mon Sep 17 00:00:00 2001 From: Paul Mumma Date: Tue, 20 May 2014 20:38:31 -0700 Subject: [PATCH 01/14] Trying again to commit my code --- blog.txt | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 blog.txt diff --git a/blog.txt b/blog.txt new file mode 100644 index 0000000..2f572cd --- /dev/null +++ b/blog.txt @@ -0,0 +1,6 @@ +== +Paul's blog post +== + +Name: Paul Mumma +URL: www.paulmumma.com/blog \ No newline at end of file From 1bff8ddeba2752fbfdf92845647168e85ba7d5ee Mon Sep 17 00:00:00 2001 From: Paul Mumma Date: Tue, 20 May 2014 20:41:50 -0700 Subject: [PATCH 02/14] commit stuff --- 01_Dev_Workflow/slides/slides_01.md | 310 ++--- 02_Variables_Conditionals/slides/slides_02.md | 422 +++---- 03_Collections_Loops/slides/slides_03.md | 1044 ++++++++--------- 04_Collections_APIs/slides/slides_04.md | 358 +++--- 05_Classes_Objects/slides/slides_05.md | 504 ++++---- 11_Lab_Session/slides/slides_11.md | 48 +- 12_Authentication/slides/slides_12.md | 556 ++++----- 7 files changed, 1621 insertions(+), 1621 deletions(-) diff --git a/01_Dev_Workflow/slides/slides_01.md b/01_Dev_Workflow/slides/slides_01.md index 29c10e7..e1b885f 100644 --- a/01_Dev_Workflow/slides/slides_01.md +++ b/01_Dev_Workflow/slides/slides_01.md @@ -1,33 +1,33 @@ -![GeneralAssemb.ly](https://github.com/generalassembly/ga-ruby-on-rails-for-devs/raw/master/images/ga.png "GeneralAssemb.ly") - -#BEWD - Working Like A Developer - -###Instructor Name - -Instructors current role. - ---- - - -##Agenda - -* Intros -* What is Web Development? -* Bash Commands -* Using GitHub - ---- - - -##Introductions - -Your course producer can help you with this. - ---- - -##Course Administration -###Lets Get This Out Of The Way - +![GeneralAssemb.ly](https://github.com/generalassembly/ga-ruby-on-rails-for-devs/raw/master/images/ga.png "GeneralAssemb.ly") + +#BEWD - Working Like A Developer + +###Instructor Name + +Instructors current role. + +--- + + +##Agenda + +* Intros +* What is Web Development? +* Bash Commands +* Using GitHub + +--- + + +##Introductions + +Your course producer can help you with this. + +--- + +##Course Administration +###Lets Get This Out Of The Way + During this course we will learn (at a high level): * Command Line / Terminal @@ -36,77 +36,77 @@ During this course we will learn (at a high level): * Rails web application framework * (Basic) Database Modeling - -To pass the course you will need to: -* Complete at least 80% of all assigned homework -* Complete a final project - ---- - -##Course Administration - -* What you will get from us - * In class labs - * Homework - * Slides / student handouts available in GitHub - * Instructor & TAs! - ---- - -##Web Development -###The Web Application Stack - -![WebStack](../../assets/command_line/server-side.jpg) - ---- - -##Web Development -###Back-end vs Front-end Development - -Let's define a few terms: - -* _Web Development_ -> apps built for the web -* _Front-End Development_ -> client / browser code (HTML, CSS, JS) -* _Back-End Development_ -> server-side code (Ruby, C#.NET) - ---- - -##Work Like a Developer -###Integrate into the developer community - -* Choose the right OS, editors, & tools for your projects. -* Leverage the online community's vast libraries and documentation. -* Spread the knowledge you gain, and give back to the community when you can. -* Take pride & and joy in what you work on. -* Be efficient: - * Use the keyboard as much as possible - * If you find yourself doing the same thing repeatedly, automate it - ---- - -##The Command Line -###What is it? - -The command line is a terminal giving you direct access to your operating system. You can enter simple commands to perform a variety of functions. - -Many of the tasks we need to carry out (such as committing our code) are best performed in the command line. - ---- - -##The Command Line -###How do I start? - -For Macs: - -* Open the "Terminal" app -* For a better experience, download and install "iTerm 2", which is a replacement app that is slightly better. - - -For Windows: - -* Open the "Command Prompt" application -* For a better experience, try "Console" (http://sourceforge.net/projects/console/) - + +To pass the course you will need to: +* Complete at least 80% of all assigned homework +* Complete a final project + +--- + +##Course Administration + +* What you will get from us + * In class labs + * Homework + * Slides / student handouts available in GitHub + * Instructor & TAs! + +--- + +##Web Development +###The Web Application Stack + +![WebStack](../../assets/command_line/server-side.jpg) + +--- + +##Web Development +###Back-end vs Front-end Development + +Let's define a few terms: + +* _Web Development_ -> apps built for the web +* _Front-End Development_ -> client / browser code (HTML, CSS, JS) +* _Back-End Development_ -> server-side code (Ruby, C#.NET) + +--- + +##Work Like a Developer +###Integrate into the developer community + +* Choose the right OS, editors, & tools for your projects. +* Leverage the online community's vast libraries and documentation. +* Spread the knowledge you gain, and give back to the community when you can. +* Take pride & and joy in what you work on. +* Be efficient: + * Use the keyboard as much as possible + * If you find yourself doing the same thing repeatedly, automate it + +--- + +##The Command Line +###What is it? + +The command line is a terminal giving you direct access to your operating system. You can enter simple commands to perform a variety of functions. + +Many of the tasks we need to carry out (such as committing our code) are best performed in the command line. + +--- + +##The Command Line +###How do I start? + +For Macs: + +* Open the "Terminal" app +* For a better experience, download and install "iTerm 2", which is a replacement app that is slightly better. + + +For Windows: + +* Open the "Command Prompt" application +* For a better experience, try "Console" (http://sourceforge.net/projects/console/) + --- ##The Command Line @@ -119,29 +119,29 @@ For Windows: * ```ruby file.rb``` (this would run a Ruby file named file.rb) * This is the basis of how we will be writing and testing our Ruby applications in the initial portion of this course ---- - - - -![GeneralAssemb.ly](../../assets/ICL_icons/Code_along_icon_md.png) -##Command Line Basics - ---- - - -![GeneralAssemb.ly](../../assets/ICL_icons/Exercise_icon_md.png) +--- + + + +![GeneralAssemb.ly](../../assets/ICL_icons/Code_along_icon_md.png) +##Command Line Basics + +--- + + +![GeneralAssemb.ly](../../assets/ICL_icons/Exercise_icon_md.png) ##Command Line Basics Exercise - ---- - -##Git -###What Is Git? - + +--- + +##Git +###What Is Git? + * Git is a source control management tool. * Git allows you to store and update your code in a structured way. * Git includes history of changes you make, so you can create "checkpoints" and track your work better over time. -* Git is an intelligent tool, and does many things for you automatically, but can be tricky to use in some cases. It takes a bit of learning to get fully comfortable with Git. - +* Git is an intelligent tool, and does many things for you automatically, but can be tricky to use in some cases. It takes a bit of learning to get fully comfortable with Git. + --- ##Git @@ -161,16 +161,16 @@ For Windows: ![GeneralAssemb.ly](../../assets/GitHub/git_general_diagram.png) ---- - - -![GeneralAssemb.ly](../../assets/ICL_icons/Code_along_icon_md.png) -##Git Basics - ---- - - -##GitHub +--- + + +![GeneralAssemb.ly](../../assets/ICL_icons/Code_along_icon_md.png) +##Git Basics + +--- + + +##GitHub ###What is a GitHub fork? * As you work on projects in this class, we want you to use GitHub. @@ -182,28 +182,28 @@ For Windows: ##GitHub ###GitHub Forks Diagram - -![ Git In Class Diagram](../../assets/GitHub/fork_Diagram.png) - ---- - - - -![GeneralAssemb.ly](../../assets/ICL_icons/Code_along_icon_md.png) -##Git In Class - ---- - - -![GeneralAssemb.ly](../../assets/ICL_icons/Exercise_icon_md.png) -## Git It Together - ---- - - -## Homework - -* Review command line and GitHub. -* Create your first blog entry. - ---- + +![ Git In Class Diagram](../../assets/GitHub/fork_Diagram.png) + +--- + + + +![GeneralAssemb.ly](../../assets/ICL_icons/Code_along_icon_md.png) +##Git In Class + +--- + + +![GeneralAssemb.ly](../../assets/ICL_icons/Exercise_icon_md.png) +## Git It Together + +--- + + +## Homework + +* Review command line and GitHub. +* Create your first blog entry. + +--- diff --git a/02_Variables_Conditionals/slides/slides_02.md b/02_Variables_Conditionals/slides/slides_02.md index fcf4eb8..713ece0 100644 --- a/02_Variables_Conditionals/slides/slides_02.md +++ b/02_Variables_Conditionals/slides/slides_02.md @@ -1,46 +1,46 @@ -![GeneralAssemb.ly](https://github.com/generalassembly/ga-ruby-on-rails-for-devs/raw/master/images/ga.png "GeneralAssemb.ly") - -#BEWD - Variables and Conditional Logic - +![GeneralAssemb.ly](https://github.com/generalassembly/ga-ruby-on-rails-for-devs/raw/master/images/ga.png "GeneralAssemb.ly") + +#BEWD - Variables and Conditional Logic + ###Instructor Name - ---- - - -##Agenda - -* Quiz -* Intro to Ruby & irb -* Variables - * Numbers - * Strings - * Booleans -* Method Basics -* Conditional Logic -* Lab Time - ---- - -##QUIZ -1. How do I change directories using the command line? -2. What is Git and GitHub? -3. How do I add files to git? -4. What is a GitHub Repository? -5. What is the correct way to push changes to your GitHub repo? - a. git pull origin master - b. git commit -m "push to GitHub" - c. git push origin master - ---- - + +--- + + +##Agenda + +* Quiz +* Intro to Ruby & irb +* Variables + * Numbers + * Strings + * Booleans +* Method Basics +* Conditional Logic +* Lab Time + +--- + +##QUIZ +1. How do I change directories using the command line? +2. What is Git and GitHub? +3. How do I add files to git? +4. What is a GitHub Repository? +5. What is the correct way to push changes to your GitHub repo? + a. git pull origin master + b. git commit -m "push to GitHub" + c. git push origin master + +--- + ##Ruby -###A programming language - -* An open source programming language +###A programming language + +* An open source programming language * Easy to read and natural to write * Created by Yukihiro Matsumoto (aka Matz) with the goal of building a language FOR developers -* Regularly maintained and evolved (recently reached version 2.0.0) - +* Regularly maintained and evolved (recently reached version 2.0.0) +
@@ -48,9 +48,9 @@ --- ##Rails -###A web application framework - -* Open source web application framework that is built in Ruby +###A web application framework + +* Open source web application framework that is built in Ruby * Allows you to create web applications that query a database. * Created by DHH (David Heinemer Hansson) to simplify the task of building web applications, with the help of _conventions_ @@ -58,53 +58,53 @@ - - ---- - - -##Ruby & Rails -###Ruby first. - -* It will be easier to navigate a Rails project once we have a basic understanding of Ruby. + + +--- + + +##Ruby & Rails +###Ruby first. + +* It will be easier to navigate a Rails project once we have a basic understanding of Ruby. * We will first teach you how to write simple Ruby scripts as stand-alone applications -* Once we have become familiarized with Ruby, we will start building Rails applications (which are essentially groups of Ruby script files that work together) - ---- - -##Computational Thinking -###What does it mean to program? - -"Learning about “for” loops is not learning to program, any more than learning about pencils is learning to draw." - - –Bret Victor, Learnable Programming - ---- - -![GeneralAssemb.ly](http://studio.generalassemb.ly/GA_Slide_Assets/Code_along_icon_md.png) -##Robot - - +* Once we have become familiarized with Ruby, we will start building Rails applications (which are essentially groups of Ruby script files that work together) + +--- + +##Computational Thinking +###What does it mean to program? + +"Learning about “for” loops is not learning to program, any more than learning about pencils is learning to draw." + + –Bret Victor, Learnable Programming + --- -##Robot Recap -###Its about changing how you think -* Think in logical steps to solve a problem -* Use Ruby keywords to help solve those problems - * Conditional Logic +![GeneralAssemb.ly](http://studio.generalassemb.ly/GA_Slide_Assets/Code_along_icon_md.png) +##Robot + + +--- + +##Robot Recap +###Its about changing how you think +* Think in logical steps to solve a problem +* Use Ruby keywords to help solve those problems + * Conditional Logic * Iteration - ---- - + +--- + ##Programming Fundamentals * In order to start writing our own Ruby programs, we need to learn some of the basic fundamental tools * Specifically, we need to learn: * Variables * Methods * Conditions -* We will first learn the basics on their own, and then try to apply our skills in a simple interactive Ruby script - ---- +* We will first learn the basics on their own, and then try to apply our skills in a simple interactive Ruby script + +--- ##Saving Values @@ -116,37 +116,37 @@ * The action of getting the value from a variable is called **accessing** the variable * We will use all the above techniques to store values into variables, and generate new values using existing variables ---- - - -##Variables -###Storing Values - - >> name = "Steven" - => "Steven" - >> age = 2013 - 1983 - => age # 30 ---- - +--- + + +##Variables +###Storing Values + + >> name = "Steven" + => "Steven" + >> age = 2013 - 1983 + => age # 30 +--- + ##Data Types * The types of different values we support include numbers, text, and other more complex ones we'll see in the future -* Ruby has its own names for these: - - 1 #Fixnum - 1.99 #Float - 'Hi! String here!' #String - "I'm a string tool" #String - +* Ruby has its own names for these: + + 1 #Fixnum + 1.99 #Float + 'Hi! String here!' #String + "I'm a string tool" #String + --- - -![GeneralAssemb.ly](http://studio.generalassemb.ly/GA_Slide_Assets/Code_along_icon_md.png) + +![GeneralAssemb.ly](http://studio.generalassemb.ly/GA_Slide_Assets/Code_along_icon_md.png) ##Variables - + Let's learn how to assign and access simple integer and string variables ---- +--- ##Saving Code @@ -159,17 +159,17 @@ Let's learn how to assign and access simple integer and string variables --- -##Math in Ruby -###Ruby Arithmetic Operators - -![Ruby Arithmetic](../../assets/ruby/ruby_arithmetic.jpg) - +##Math in Ruby +###Ruby Arithmetic Operators + +![Ruby Arithmetic](../../assets/ruby/ruby_arithmetic.jpg) + --- - -![GeneralAssemb.ly](http://studio.generalassemb.ly/GA_Slide_Assets/Code_along_icon_md.png) + +![GeneralAssemb.ly](http://studio.generalassemb.ly/GA_Slide_Assets/Code_along_icon_md.png) ##Methods - + Let's learn how to call simple methods, and how to declare our own methods. --- @@ -182,110 +182,110 @@ Let's learn how to call simple methods, and how to declare our own methods. * Declaring a method does NOT run the method immediately * If the method takes in variables to use while it is doing its tasks, those are called **parameters** ---- - - -![GeneralAssemb.ly](http://studio.generalassemb.ly/GA_Slide_Assets/Code_along_icon_md.png) -##Teddit - Strings - -Teddit is a news aggregator we will build during this course. - ---- - - -##More Data Types -###Booleans +--- + + +![GeneralAssemb.ly](http://studio.generalassemb.ly/GA_Slide_Assets/Code_along_icon_md.png) +##Teddit - Strings + +Teddit is a news aggregator we will build during this course. + +--- + + +##More Data Types +###Booleans * Besides strings and integers, Ruby also has a Boolean data type * A boolean is a simple value that is either ```true``` or ```false``` -* When different data types are compared to each other, the result of that comparison is a boolean result (e.g. 5 < 7 => true) - ---- - - -##Boolean -###Logic Operators - - -![](../../assets/ruby/logic_operators.png) - - ---- - -![GeneralAssemb.ly](http://studio.generalassemb.ly/GA_Slide_Assets/Code_along_icon_md.png) -##Booleans - ---- - - -##Variables & Data Types -###Recap - -Data Types - +* When different data types are compared to each other, the result of that comparison is a boolean result (e.g. 5 < 7 => true) + +--- + + +##Boolean +###Logic Operators + + +![](../../assets/ruby/logic_operators.png) + + +--- + +![GeneralAssemb.ly](http://studio.generalassemb.ly/GA_Slide_Assets/Code_along_icon_md.png) +##Booleans + +--- + + +##Variables & Data Types +###Recap + +Data Types + * Number -* Float (number with decimals) -* String -* Booleans - -Variables - -* Store values -* Can be passed to methods as parameters - ---- - -##Conditional Logic -###Decision Time - -It's either TRUE or FALSE (like booleans) - -If you are greater than 18 -you are an adult - - if age > 18 - puts "You are an adult" - end - ---- - - -##Conditional Logic -###Multiple Conditions - - - guess = 7 - if guess > 5 - puts "Too high!" - elseif guess < 5 - puts "Too Low!" - else - puts "You've guessed my hidden digit!" - end - ---- - -##Conditional Logic -###Multiple Conditions - -![truth_table](../../assets/ruby/truth_table.png) - ---- - -![GeneralAssemb.ly](http://studio.generalassemb.ly/GA_Slide_Assets/Exercise_icon_md.png) -##Lab Time -* Conditional Teddit - ---- - - -## Homework +* Float (number with decimals) +* String +* Booleans + +Variables + +* Store values +* Can be passed to methods as parameters + +--- + +##Conditional Logic +###Decision Time + +It's either TRUE or FALSE (like booleans) + +If you are greater than 18 +you are an adult + + if age > 18 + puts "You are an adult" + end + +--- + + +##Conditional Logic +###Multiple Conditions + + + guess = 7 + if guess > 5 + puts "Too high!" + elseif guess < 5 + puts "Too Low!" + else + puts "You've guessed my hidden digit!" + end + +--- + +##Conditional Logic +###Multiple Conditions + +![truth_table](../../assets/ruby/truth_table.png) + +--- + +![GeneralAssemb.ly](http://studio.generalassemb.ly/GA_Slide_Assets/Exercise_icon_md.png) +##Lab Time +* Conditional Teddit + +--- + + +## Homework ###Secret Number -Let's see a demo of Secret Number - -* HW 1 - Secret Number - * Secret number is a game we will incrementally build for homework during the Ruby portion of the course. - Players must guess a secret number and your program will provide feedback. ---- - +Let's see a demo of Secret Number + +* HW 1 - Secret Number + * Secret number is a game we will incrementally build for homework during the Ruby portion of the course. + Players must guess a secret number and your program will provide feedback. +--- + diff --git a/03_Collections_Loops/slides/slides_03.md b/03_Collections_Loops/slides/slides_03.md index e48e2d8..cee770a 100644 --- a/03_Collections_Loops/slides/slides_03.md +++ b/03_Collections_Loops/slides/slides_03.md @@ -1,522 +1,522 @@ - - -#BEWD - Collections & Loops - -###Instructor Name - ---- - - -##Agenda - -* Iteration - Loops -* Collections - * Arrays - * Hashes - - ---- - - -##Iteration -###Repetition -###Repetition -###Repetition - - - ---- - - -##Iteration (Ruby-esque Loops) -###Times Iterator - - 3.times do - puts "going…" - end - puts "gone" - - # going... - # going... - # going... - # gone ---- - - -##Iteration (Ruby-esque Loops) -###.upto - - 1.upto(3) do |num| - puts "#{num}.going" - end - - # 1. going - # 2. going - # 3. going - ---- - - -##Iteration (Ruby-esque Loops) -###.downto - - 3.downto(1) do |guess| - puts "You have #{guess} guesses left" - end - - # You have 3 guesses left - # You have 2 guesses left - # You have 1 guesses left - ---- - - - -##Iteration (Ruby-esque Loops) -###Less common in Ruby - -* These loops are less common in Ruby, but good to know as a programmer. - - * X.times - * upto - * downto - -* For additional help with syntax, see the Resources at the end of the slides. - ---- - - -##Conditional Loops - - count = 10 - while count > 0 - puts "Looping" - count -=1 - end - - count = 10 - until count < 1 - puts "Looping" - count -= 1 - end - - count = 10 - loop do - break if count < 1 - puts "Looping" - count -= 1 - end - ---- - - - -##Loop - ---- - - -##Iteration Recap -###Recap - -* Iteration in programming allows us to keep our code DRY -* Loops are used to repeat lines of code -* Common or Ruby-esque loops are - * .times - * .upto - * .downto - * .each (we will see in a moment) - ---- - - -##Collections -###Working with Collections in Ruby - ---- - - -##Collections -###Arrays - -![accordion folder](../../assets/ruby/accordian.jpg) - ---- - - -##Arrays -###Find by Index - -![Array Indexing](../../assets/ruby/array_index_diagram.png) - ---- - - -##Arrays -###Find by Index - - my_array = ["NYC", "LA", "SYD", "LDN"] - my_array[0] #"NYC" - my_array[1] #"LA" - my_array[-1] #"LDN" - ---- - - -##Arrays -###Find by Position - -![Array position](../../assets/ruby/arrays_position_diagram.png) - ---- - - -##Arrays -###Find by Position - - my_array = ["NYC", "LA", "SYD", "LDN"] - my_array.first #"NYC" - my_array.last #"LDN" - - - # In rails... - # Will not work in IRB - my_array = ["NYC", "LA", "SYD", "LDN"] - my_array.second - my_array.third - my_array.forth - my_array.fifth - my_array.forty_two # known as the reddit - ---- - - -##Arrays -###Array Methods - - name = "Salman" - name.upcase - - my_array = ["NYC", "LA", "SYD", "LDN"] - my_array.reverse - ---- - - - -##Arrays - -to irb! - - ---- - - - -##Arrays - ---- - - -##Arrays -###Recap - - -* A collection of data -* Can search an array by index or position -* Arrays are objects and therefore have methods. - ---- - - -##Collections -###Hashes - -![Labeled Accordion](../../assets/ruby/labeled_accordian.jpeg) - -* Often referred to as dictionaries -* Each entry in a hash needs a *key* and a *value* -* If you access a hash at a specific key, it will return the value at that key - ---- - - -##Hashes -###Find by key - - ga_markets = {"NYC" => "New York City", "LA" => "Los Angeles", "SYD" => "Sydney", "LDN" => "London"} - - ga_markets["NYC"] - ga_markets["LA"] - ga_markets["SYD"] - -"New York City" - -"Los Angeles" - -"Sydney" - ---- - - -##Hashes -###Setting Values - - user_hash = {} - user_hash["name"] = "Salman" - user_hash["favorite_color"] = "Green" - user_hash - - >> {"name"=>"Salman", "favorite_color"=>"Green"} - ---- - - -##Symbols -###New Ruby type - -- A symbol is a special type of object in ruby, used extensively -- It is always preceded by a colon -- Cannot contain spaces or numbers -- Symbols are used because: - - they are immutable and take less memory - - they are easier to compare to other objects - - they are cleaner in syntax -- Examples: - - ```:hello``` - - ```:this_is_a_symbol``` - ---- - - -##Symbols -###Primarily used as keys for hashes - - ga_markets = {} - ga_markets = {:NYC => "New York City"} - ga_markets[:LA] = "Los Angeles" - ga_markets - - >> {:NYC => "New York City", :LA => "Los Angeles"} - - ---- - - - -##Hash -###Methods - - user = {:user_name => "SalmanAnsari", :email => "salman.ansari@gmail.com"} - - user.has_key? :email #true - user.key? :email #true - user.include? :email #true - - user.has_value? "SalmanAnsari" #true (note: extremely inefficient!) - ---- - -##Hash -###Ruby 1.9+ Alternate Syntax - - user = {:user_name => "SalmanAnsari", :email => "salman.ansari@gmail.com"} - - # becomes - - user = {user: "SalmanAnsari", email: "salman.ansari@gmail.com"} - - # a little bit more concise - # more closely matches JSON format - # considered an 'alternate' syntax, not a replacement - ---- - - - -##Collections -###Array of Hashes - - users = [ - {:user => "Salman Ansari", :role => "Instructor"}, - {:user => "Brooks Swinnerton", :role=> "TA"} - {:user => "Brian Fountain", :role => "TA"] - ] - - - # Alternate syntax for Ruby 1.9+ - - users = [ - {user: "Salman Ansari", role: "Instructor"}, - {user: "Brooks Swinnerton", role: "TA"}, - {user: "Brian Fountain", role: "TA"} - ] - - ---- - - -##Iterating Over Collections -###.each - - ga_markets = ["NYC", "LA", "SYD", "LDN"] - - ga_markets.each {|market| puts market} - - ---- - - - -##Lab Time -###Teddit Collections - ---- - - -##Recap -###Iterating Over Collections - - ---- - -## Homework - - -Continue work on Secret Number. Due next class (lesson 4) - ---- - - -## Resources: Collections, Loops and APIs - - -###Cheat Sheet - -####Arrays - -__Creating Arrays__ - -```ruby -my_array = ["Apples", "Oranges", "Pears"] -``` - -> ["Apples", "Oranges", "Pears"] - -```ruby -my_array = Array.new -``` - -> [] - -```ruby -Array.new(3) -``` - -> [nil, nil, nil] - -```ruby -Array.new(3, "BEWD") -``` - -> ["BEWD", "BEWD", "BEWD"] - -__Assessing Elements__ - -```ruby -arr = ["NYC", "LDN", "LA", "SF", "BOS", "BER"] -arr[0] -arr[100] -arr[-3] -``` - -> NYC - -> nil - -> SF - -```ruby -arr[2, 3] #=> [3, 4, 5] -``` - -> ["LA", "SF", "BOS"] - -```ruby -arr[1..4] -``` - -> [LDN, LA, SF, BOS] - -####Hashes - -```ruby - GA_Markets = { "New York City"=>"NYC", "London"=>"LDN", "Los Angeles"=>"LA", "San Francisco"=>"SF", "Boston"=>"BOS", "Berlin"=>"BER" } - - GA_Markets["London"] -``` - -> "LDN" - -```ruby - super_heros = { batman: "Bruce Wayne", superman: "Clark Kent", spiderman: "Peter Parker"} - - super_heros[:superman] -``` - -> "Clark Kent" - -####Loops - -__Iterator loop__ - -```ruby -4.times do - puts "This will be printed 4 times" -end -``` - -> This will be printed 4 times - -> This will be printed 4 times - -> This will be printed 4 times - -> This will be printed 4 times - -__Each Loop__ - -```ruby - # A list of GA Courses - courses = [ "FEWD", "BEWD", "CSF" ] - - names.each do|n| - puts "GA has a course on #{n}" - end -``` - -> GA has a course on FEWD - -> GA has a course on BEWD - -> GA has a course on CSF - - -###Tips, Tricks & Motivation - -- [The Best Way to Learn Ruby & Rails](http://astonj.com/tech/best-way-to-learn-ruby-rails/) -- What is iteration - [article](http://www.computerhope.com/jargon/i/iteration.htm) - - -###Still Feel Lost? -####Catch Up With These Resources - -- Teddit Hashes Answer [Video](http://vimeo.com/gatv/review/67752035/a90db9177f) by Steven Nuñez on behalf of General Assembly - - password=> BEWD_GA - -- Arrays [Ruby Docs](http://ruby-doc.org/core-2.0/Array.html) -- Hashes [Ruby Docs](http://ruby-doc.org/core-2.0/Hash.html) -- Hashes and Arrays [Tutorial](http://www.codecademy.com/courses/ruby-beginner-en-F3loB?curriculum_id=5059f8619189a5000201fbcb) -- [*“Ruby-esque”* Loops](http://ruby.about.com/od/rubyfeatures/a/loops_2.htm) see page 1 for more ruby loops not covered in class. - - + + +#BEWD - Collections & Loops + +###Instructor Name + +--- + + +##Agenda + +* Iteration - Loops +* Collections + * Arrays + * Hashes + + +--- + + +##Iteration +###Repetition +###Repetition +###Repetition + + + +--- + + +##Iteration (Ruby-esque Loops) +###Times Iterator + + 3.times do + puts "going…" + end + puts "gone" + + # going... + # going... + # going... + # gone +--- + + +##Iteration (Ruby-esque Loops) +###.upto + + 1.upto(3) do |num| + puts "#{num}.going" + end + + # 1. going + # 2. going + # 3. going + +--- + + +##Iteration (Ruby-esque Loops) +###.downto + + 3.downto(1) do |guess| + puts "You have #{guess} guesses left" + end + + # You have 3 guesses left + # You have 2 guesses left + # You have 1 guesses left + +--- + + + +##Iteration (Ruby-esque Loops) +###Less common in Ruby + +* These loops are less common in Ruby, but good to know as a programmer. + + * X.times + * upto + * downto + +* For additional help with syntax, see the Resources at the end of the slides. + +--- + + +##Conditional Loops + + count = 10 + while count > 0 + puts "Looping" + count -=1 + end + + count = 10 + until count < 1 + puts "Looping" + count -= 1 + end + + count = 10 + loop do + break if count < 1 + puts "Looping" + count -= 1 + end + +--- + + + +##Loop + +--- + + +##Iteration Recap +###Recap + +* Iteration in programming allows us to keep our code DRY +* Loops are used to repeat lines of code +* Common or Ruby-esque loops are + * .times + * .upto + * .downto + * .each (we will see in a moment) + +--- + + +##Collections +###Working with Collections in Ruby + +--- + + +##Collections +###Arrays + +![accordion folder](../../assets/ruby/accordian.jpg) + +--- + + +##Arrays +###Find by Index + +![Array Indexing](../../assets/ruby/array_index_diagram.png) + +--- + + +##Arrays +###Find by Index + + my_array = ["NYC", "LA", "SYD", "LDN"] + my_array[0] #"NYC" + my_array[1] #"LA" + my_array[-1] #"LDN" + +--- + + +##Arrays +###Find by Position + +![Array position](../../assets/ruby/arrays_position_diagram.png) + +--- + + +##Arrays +###Find by Position + + my_array = ["NYC", "LA", "SYD", "LDN"] + my_array.first #"NYC" + my_array.last #"LDN" + + + # In rails... + # Will not work in IRB + my_array = ["NYC", "LA", "SYD", "LDN"] + my_array.second + my_array.third + my_array.forth + my_array.fifth + my_array.forty_two # known as the reddit + +--- + + +##Arrays +###Array Methods + + name = "Salman" + name.upcase + + my_array = ["NYC", "LA", "SYD", "LDN"] + my_array.reverse + +--- + + + +##Arrays + +to irb! + + +--- + + + +##Arrays + +--- + + +##Arrays +###Recap + + +* A collection of data +* Can search an array by index or position +* Arrays are objects and therefore have methods. + +--- + + +##Collections +###Hashes + +![Labeled Accordion](../../assets/ruby/labeled_accordian.jpeg) + +* Often referred to as dictionaries +* Each entry in a hash needs a *key* and a *value* +* If you access a hash at a specific key, it will return the value at that key + +--- + + +##Hashes +###Find by key + + ga_markets = {"NYC" => "New York City", "LA" => "Los Angeles", "SYD" => "Sydney", "LDN" => "London"} + + ga_markets["NYC"] + ga_markets["LA"] + ga_markets["SYD"] + +"New York City" + +"Los Angeles" + +"Sydney" + +--- + + +##Hashes +###Setting Values + + user_hash = {} + user_hash["name"] = "Salman" + user_hash["favorite_color"] = "Green" + user_hash + + >> {"name"=>"Salman", "favorite_color"=>"Green"} + +--- + + +##Symbols +###New Ruby type + +- A symbol is a special type of object in ruby, used extensively +- It is always preceded by a colon +- Cannot contain spaces or numbers +- Symbols are used because: + - they are immutable and take less memory + - they are easier to compare to other objects + - they are cleaner in syntax +- Examples: + - ```:hello``` + - ```:this_is_a_symbol``` + +--- + + +##Symbols +###Primarily used as keys for hashes + + ga_markets = {} + ga_markets = {:NYC => "New York City"} + ga_markets[:LA] = "Los Angeles" + ga_markets + + >> {:NYC => "New York City", :LA => "Los Angeles"} + + +--- + + + +##Hash +###Methods + + user = {:user_name => "SalmanAnsari", :email => "salman.ansari@gmail.com"} + + user.has_key? :email #true + user.key? :email #true + user.include? :email #true + + user.has_value? "SalmanAnsari" #true (note: extremely inefficient!) + +--- + +##Hash +###Ruby 1.9+ Alternate Syntax + + user = {:user_name => "SalmanAnsari", :email => "salman.ansari@gmail.com"} + + # becomes + + user = {user: "SalmanAnsari", email: "salman.ansari@gmail.com"} + + # a little bit more concise + # more closely matches JSON format + # considered an 'alternate' syntax, not a replacement + +--- + + + +##Collections +###Array of Hashes + + users = [ + {:user => "Salman Ansari", :role => "Instructor"}, + {:user => "Brooks Swinnerton", :role=> "TA"} + {:user => "Brian Fountain", :role => "TA"] + ] + + + # Alternate syntax for Ruby 1.9+ + + users = [ + {user: "Salman Ansari", role: "Instructor"}, + {user: "Brooks Swinnerton", role: "TA"}, + {user: "Brian Fountain", role: "TA"} + ] + + +--- + + +##Iterating Over Collections +###.each + + ga_markets = ["NYC", "LA", "SYD", "LDN"] + + ga_markets.each {|market| puts market} + + +--- + + + +##Lab Time +###Teddit Collections + +--- + + +##Recap +###Iterating Over Collections + + +--- + +## Homework + + +Continue work on Secret Number. Due next class (lesson 4) + +--- + + +## Resources: Collections, Loops and APIs + + +###Cheat Sheet + +####Arrays + +__Creating Arrays__ + +```ruby +my_array = ["Apples", "Oranges", "Pears"] +``` + +> ["Apples", "Oranges", "Pears"] + +```ruby +my_array = Array.new +``` + +> [] + +```ruby +Array.new(3) +``` + +> [nil, nil, nil] + +```ruby +Array.new(3, "BEWD") +``` + +> ["BEWD", "BEWD", "BEWD"] + +__Assessing Elements__ + +```ruby +arr = ["NYC", "LDN", "LA", "SF", "BOS", "BER"] +arr[0] +arr[100] +arr[-3] +``` + +> NYC + +> nil + +> SF + +```ruby +arr[2, 3] #=> [3, 4, 5] +``` + +> ["LA", "SF", "BOS"] + +```ruby +arr[1..4] +``` + +> [LDN, LA, SF, BOS] + +####Hashes + +```ruby + GA_Markets = { "New York City"=>"NYC", "London"=>"LDN", "Los Angeles"=>"LA", "San Francisco"=>"SF", "Boston"=>"BOS", "Berlin"=>"BER" } + + GA_Markets["London"] +``` + +> "LDN" + +```ruby + super_heros = { batman: "Bruce Wayne", superman: "Clark Kent", spiderman: "Peter Parker"} + + super_heros[:superman] +``` + +> "Clark Kent" + +####Loops + +__Iterator loop__ + +```ruby +4.times do + puts "This will be printed 4 times" +end +``` + +> This will be printed 4 times + +> This will be printed 4 times + +> This will be printed 4 times + +> This will be printed 4 times + +__Each Loop__ + +```ruby + # A list of GA Courses + courses = [ "FEWD", "BEWD", "CSF" ] + + names.each do|n| + puts "GA has a course on #{n}" + end +``` + +> GA has a course on FEWD + +> GA has a course on BEWD + +> GA has a course on CSF + + +###Tips, Tricks & Motivation + +- [The Best Way to Learn Ruby & Rails](http://astonj.com/tech/best-way-to-learn-ruby-rails/) +- What is iteration - [article](http://www.computerhope.com/jargon/i/iteration.htm) + + +###Still Feel Lost? +####Catch Up With These Resources + +- Teddit Hashes Answer [Video](http://vimeo.com/gatv/review/67752035/a90db9177f) by Steven Nuñez on behalf of General Assembly + - password=> BEWD_GA + +- Arrays [Ruby Docs](http://ruby-doc.org/core-2.0/Array.html) +- Hashes [Ruby Docs](http://ruby-doc.org/core-2.0/Hash.html) +- Hashes and Arrays [Tutorial](http://www.codecademy.com/courses/ruby-beginner-en-F3loB?curriculum_id=5059f8619189a5000201fbcb) +- [*“Ruby-esque”* Loops](http://ruby.about.com/od/rubyfeatures/a/loops_2.htm) see page 1 for more ruby loops not covered in class. + + diff --git a/04_Collections_APIs/slides/slides_04.md b/04_Collections_APIs/slides/slides_04.md index 9cfe12f..338aaff 100644 --- a/04_Collections_APIs/slides/slides_04.md +++ b/04_Collections_APIs/slides/slides_04.md @@ -1,179 +1,179 @@ - - -#BEWD - Collections, Loops & APIs - -###Instructor Name - ---- - - -##Agenda - -* Recap - * Quick Fire -* Practical Application Of Collections & Loops (APIs) -* Lab Time - ---- - - - -##Quick Fire - Fizz Buzz - ---- - - -##Quick Fire -###Fizz Buzz - -TIME : 30 min - -* Write a program that prints numbers from 1 to 100. - -* But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. - -* For numbers which are multiples of both three and five print “FizzBuzz”. - ---- - - - -##Recap - -* Variables -* Conditionals -* Iteration -* Collections - - ---- - - -##Working With Collections -###Let's get practical - - ---- - - -##APIs -###Application Programming Interface - - ---- - - -##APIs -###Working with APIs - -1. Ask for some data -2. Convert it into a format we can work with -3. Do cool stuff - ---- - - -##API -###Ask for Data - - -* We need to use a gem to ask for data. - - $ gem install rest-client - ---- - - -##API -###Convert into a format we can work with - - -* JSON - JavaScript Object Notation - - '{"NY":"New York","LA":"Los Angeles","SYD":"Sydney","LDN":"London"}' - - ---- - - -##Do Cool Stuff - - -Getting Stories - - ---- - - - - -##Teddit API News - ---- - - -## Homework - -* Continue review - ---- - - -
-## Resources: Collections, Loops & APIs - -###Cheat Sheet - -####Array of Hashes - -```ruby - super_heros =[{ hero: 'Batman', secret_identity: 'Bruce Wayne'}, - {hero: 'Superman', secret_identity: 'Clark Kent'}, - {hero: 'Spiderman', secret_identity: 'Peter Parker'}] -``` - - -####.each & .map - -```ruby - super_heros.map do |super_hero| - puts "#{super_hero[:hero]} is #{super_hero[:secret_identity]}" - end -``` - -```ruby - super_heros.each do |super_hero| - puts "#{super_hero[:hero]} is #{super_hero[:secret_identity]}" - end -``` - -* .each returns the original array. -* Map returns a new array with the results you added. - - -###Tips, Tricks & Motivation - - -* [Writing A REST Client in Ruby](http://www.alphadevx.com/a/88-Writing-a-REST-Client-in-Ruby) - -* [Use RestClient for HTTP requests in Ruby](https://coderwall.com/p/bmgapg) - -* [Understand Rest Client (Advanced)](http://www.ibm.com/developerworks/library/os-understand-rest-ruby/) - -* [JSON What It Is, How It Works and How To Use It](http://www.copterlabs.com/blog/json-what-it-is-how-it-works-how-to-use-it/) - * The code in this article is JavaScript. Read the article to get a better understanding of what is JSON don't worry about the code. - -__Map versus do__ - -* [Difference Between Map And Each](http://stackoverflow.com/questions/9586989/difference-between-map-and-each) - -* [Video about Difference Between Map and Each](http://www.youtube.com/watch?v=jJHzwgPl5lA) - - -###Still Feel Lost? -####Catch Up With These Resources - -- Fizz Buzz Answer [Video](https://vimeo.com/67752034) -- Rest Client [Video](http://vimeo.com/67132957) by Steven Nuñez on behalf of General Assembly -- - - password=> testBEWD + + +#BEWD - Collections, Loops & APIs + +###Instructor Name + +--- + + +##Agenda + +* Recap + * Quick Fire +* Practical Application Of Collections & Loops (APIs) +* Lab Time + +--- + + + +##Quick Fire - Fizz Buzz + +--- + + +##Quick Fire +###Fizz Buzz + +TIME : 30 min + +* Write a program that prints numbers from 1 to 100. + +* But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. + +* For numbers which are multiples of both three and five print “FizzBuzz”. + +--- + + + +##Recap + +* Variables +* Conditionals +* Iteration +* Collections + + +--- + + +##Working With Collections +###Let's get practical + + +--- + + +##APIs +###Application Programming Interface + + +--- + + +##APIs +###Working with APIs + +1. Ask for some data +2. Convert it into a format we can work with +3. Do cool stuff + +--- + + +##API +###Ask for Data + + +* We need to use a gem to ask for data. + + $ gem install rest-client + +--- + + +##API +###Convert into a format we can work with + + +* JSON - JavaScript Object Notation + + '{"NY":"New York","LA":"Los Angeles","SYD":"Sydney","LDN":"London"}' + + +--- + + +##Do Cool Stuff + + +Getting Stories + + +--- + + + + +##Teddit API News + +--- + + +## Homework + +* Continue review + +--- + + +
+## Resources: Collections, Loops & APIs + +###Cheat Sheet + +####Array of Hashes + +```ruby + super_heros =[{ hero: 'Batman', secret_identity: 'Bruce Wayne'}, + {hero: 'Superman', secret_identity: 'Clark Kent'}, + {hero: 'Spiderman', secret_identity: 'Peter Parker'}] +``` + + +####.each & .map + +```ruby + super_heros.map do |super_hero| + puts "#{super_hero[:hero]} is #{super_hero[:secret_identity]}" + end +``` + +```ruby + super_heros.each do |super_hero| + puts "#{super_hero[:hero]} is #{super_hero[:secret_identity]}" + end +``` + +* .each returns the original array. +* Map returns a new array with the results you added. + + +###Tips, Tricks & Motivation + + +* [Writing A REST Client in Ruby](http://www.alphadevx.com/a/88-Writing-a-REST-Client-in-Ruby) + +* [Use RestClient for HTTP requests in Ruby](https://coderwall.com/p/bmgapg) + +* [Understand Rest Client (Advanced)](http://www.ibm.com/developerworks/library/os-understand-rest-ruby/) + +* [JSON What It Is, How It Works and How To Use It](http://www.copterlabs.com/blog/json-what-it-is-how-it-works-how-to-use-it/) + * The code in this article is JavaScript. Read the article to get a better understanding of what is JSON don't worry about the code. + +__Map versus do__ + +* [Difference Between Map And Each](http://stackoverflow.com/questions/9586989/difference-between-map-and-each) + +* [Video about Difference Between Map and Each](http://www.youtube.com/watch?v=jJHzwgPl5lA) + + +###Still Feel Lost? +####Catch Up With These Resources + +- Fizz Buzz Answer [Video](https://vimeo.com/67752034) +- Rest Client [Video](http://vimeo.com/67132957) by Steven Nuñez on behalf of General Assembly +- + - password=> testBEWD diff --git a/05_Classes_Objects/slides/slides_05.md b/05_Classes_Objects/slides/slides_05.md index 5e2f76e..5637d94 100644 --- a/05_Classes_Objects/slides/slides_05.md +++ b/05_Classes_Objects/slides/slides_05.md @@ -1,252 +1,252 @@ - - -#BEWD - Classes and Objects - -###Instructor Name - ---- - - -##Agenda - -* Creating Classes & Objects -* Lab Time - ---- - - -##From Hashes to Classes -###Hashes pros and cons - -What are some pros and cons of using hashes? - ---- - - -##Classes & Objects -###Classes to the rescue - -* What is a class? -* What is an object? -* Why/when to use them? - ---- - - - -##Creating Objects - - ---- - -##Creating Objects -###Recap - -* Adding variables to a class - - # Hashes - story = {} - story[:title] = "Sand angry with flip-flops" - story[:title] #=> Returns your value - - - # With an object - class Story - attr_accessor :title - end - - - story = Story.new - story.title = "Sand angry with flip-flops" - story.title #=> Returns your value - ---- - - -##Creating Objects -###Recap - -* Adding methods to our class - - class Story - attr_accessor :title, :category, :upvotes - def upvote! - @upvotes += 1 - end - end - - story = Story.new - story.title = "Fruit Flies find fleas facetious" - story.category = "Turf War" - story.upvotes = 1 - - story.upvote! - story.upvotes #=> 2 ---- - - - -##Apartment - ---- - - -##Apartment -###Recap - -* The initialize method is invoked when Apartment.new is called -* to_s method called automatically on objects interpolated in a string (e.g. with puts) -* to_s can be overridden: - - class My_Class - def to_s - "The puts method was called." - end - end - - >> my_object = My_Class.new - >> puts my_object - The puts method was called. - => nil - ---- - - -##Apartment -###Recap - -* Classes allow us to keep code DRY. -* In object oriented programs variables have scope (key scopes are local vs @instance). - * attr_accessor allows a variable to be accessed outside of a method -* We can create class methods by using self.method_name. - * Class methods (e.g. Apartment.new) can be called on a class (which is an object too!) - ---- - - -##Classes & Objects -###Classes in separate .rb files - - ---- - -##Classes & Objects -###Too many classes in one .rb file. - - # blt.rb - class BLT - #… - end - - class Bacon - #… - end - - class Lettuce - #… - end - - class Tomato - #… - end - ---- - - -##Classes & Objects -###Everyone Gets a File! - - # blt.rb - require_relative 'bacon' - require_relative 'lettuce' - require_relative 'tomato' - - class BLT - #… - end - ---- - -##Classes & Objects -###Creating a link between classes in separate .rb file - -* require -* require_relative (we've seen this when working with APIs) -* $LOAD_PATH.unshift(File.dirname(__FILE__)) (use to load files in irb) - ---- - -## Homework - -* Midterm due lesson 8. - ---- - - - -##Lab Time - -1. Apartment Objects -2. Secret Number Objects - ---- - - -
-## RESOURCES: Classes & Objects - -###Cheat Sheet - -####Classes & Objects - -__Create A Class__ - -```ruby - class class_name - #variables and method for this class. - end -``` - -__Creating Objects__ - -```ruby - class GA_course - def initialize (course_name) - @course_name = course_name - end - - def announce_course - puts "GA has a course on #{@course_name}" - end - end - - my_course = GA_course.new("BEWD") - other_course = GA_course.new("UXD") - - my_course.announce_course - other_course.announce_course -``` ->GA has a course on BEWD - ->GA has a course on UXD - - -__Variable Scope__ - - -| Scope |Example| Explanation| -| ------------- |:-------------|:-------------------| -| Local | @name | Available in the same method| -| Instance | name | Unique value for each instance of a class available from any method in that class.| -| Class | @@name | Same shared value for all instances of a class, available from any method of that class.| -| Global | $name | Same shared value for all code running within a single Ruby program.| - - -###Still Feel Lost? -####Catch Up With These Resources - -- What is Object Oriented Programming [video](http://www.youtube.com/watch?feature=endscreen&v=SS-9y0H3Si8&NR=1) -- What is Object Oriented Programming [Book Chapter](http://ruby.bastardsbook.com/chapters/oops/) -- Introduction to Objects [Ruby Monk](http://rubymonk.com/learning/books/1-ruby-primer/chapters/6-objects/lessons/35-introduction-to-objects) -- Building your Own class [Ruby Monk](http://rubymonk.com/learning/books/1-ruby-primer/chapters/7-classes/lessons/40-building-your-own-class) - + + +#BEWD - Classes and Objects + +###Instructor Name + +--- + + +##Agenda + +* Creating Classes & Objects +* Lab Time + +--- + + +##From Hashes to Classes +###Hashes pros and cons + +What are some pros and cons of using hashes? + +--- + + +##Classes & Objects +###Classes to the rescue + +* What is a class? +* What is an object? +* Why/when to use them? + +--- + + + +##Creating Objects + + +--- + +##Creating Objects +###Recap + +* Adding variables to a class + + # Hashes + story = {} + story[:title] = "Sand angry with flip-flops" + story[:title] #=> Returns your value + + + # With an object + class Story + attr_accessor :title + end + + + story = Story.new + story.title = "Sand angry with flip-flops" + story.title #=> Returns your value + +--- + + +##Creating Objects +###Recap + +* Adding methods to our class + + class Story + attr_accessor :title, :category, :upvotes + def upvote! + @upvotes += 1 + end + end + + story = Story.new + story.title = "Fruit Flies find fleas facetious" + story.category = "Turf War" + story.upvotes = 1 + + story.upvote! + story.upvotes #=> 2 +--- + + + +##Apartment + +--- + + +##Apartment +###Recap + +* The initialize method is invoked when Apartment.new is called +* to_s method called automatically on objects interpolated in a string (e.g. with puts) +* to_s can be overridden: + + class My_Class + def to_s + "The puts method was called." + end + end + + >> my_object = My_Class.new + >> puts my_object + The puts method was called. + => nil + +--- + + +##Apartment +###Recap + +* Classes allow us to keep code DRY. +* In object oriented programs variables have scope (key scopes are local vs @instance). + * attr_accessor allows a variable to be accessed outside of a method +* We can create class methods by using self.method_name. + * Class methods (e.g. Apartment.new) can be called on a class (which is an object too!) + +--- + + +##Classes & Objects +###Classes in separate .rb files + + +--- + +##Classes & Objects +###Too many classes in one .rb file. + + # blt.rb + class BLT + #… + end + + class Bacon + #… + end + + class Lettuce + #… + end + + class Tomato + #… + end + +--- + + +##Classes & Objects +###Everyone Gets a File! + + # blt.rb + require_relative 'bacon' + require_relative 'lettuce' + require_relative 'tomato' + + class BLT + #… + end + +--- + +##Classes & Objects +###Creating a link between classes in separate .rb file + +* require +* require_relative (we've seen this when working with APIs) +* $LOAD_PATH.unshift(File.dirname(__FILE__)) (use to load files in irb) + +--- + +## Homework + +* Midterm due lesson 8. + +--- + + + +##Lab Time + +1. Apartment Objects +2. Secret Number Objects + +--- + + +
+## RESOURCES: Classes & Objects + +###Cheat Sheet + +####Classes & Objects + +__Create A Class__ + +```ruby + class class_name + #variables and method for this class. + end +``` + +__Creating Objects__ + +```ruby + class GA_course + def initialize (course_name) + @course_name = course_name + end + + def announce_course + puts "GA has a course on #{@course_name}" + end + end + + my_course = GA_course.new("BEWD") + other_course = GA_course.new("UXD") + + my_course.announce_course + other_course.announce_course +``` +>GA has a course on BEWD + +>GA has a course on UXD + + +__Variable Scope__ + + +| Scope |Example| Explanation| +| ------------- |:-------------|:-------------------| +| Local | @name | Available in the same method| +| Instance | name | Unique value for each instance of a class available from any method in that class.| +| Class | @@name | Same shared value for all instances of a class, available from any method of that class.| +| Global | $name | Same shared value for all code running within a single Ruby program.| + + +###Still Feel Lost? +####Catch Up With These Resources + +- What is Object Oriented Programming [video](http://www.youtube.com/watch?feature=endscreen&v=SS-9y0H3Si8&NR=1) +- What is Object Oriented Programming [Book Chapter](http://ruby.bastardsbook.com/chapters/oops/) +- Introduction to Objects [Ruby Monk](http://rubymonk.com/learning/books/1-ruby-primer/chapters/6-objects/lessons/35-introduction-to-objects) +- Building your Own class [Ruby Monk](http://rubymonk.com/learning/books/1-ruby-primer/chapters/7-classes/lessons/40-building-your-own-class) + diff --git a/11_Lab_Session/slides/slides_11.md b/11_Lab_Session/slides/slides_11.md index 3a6648a..227e874 100644 --- a/11_Lab_Session/slides/slides_11.md +++ b/11_Lab_Session/slides/slides_11.md @@ -1,40 +1,40 @@ -![GeneralAssemb.ly](https://github.com/generalassembly/ga-ruby-on-rails-for-devs/raw/master/images/ga.png "GeneralAssemb.ly") - -#BEWD - Review Lab Session - -###Instructor Name - ---- - - -##Agenda +![GeneralAssemb.ly](https://github.com/generalassembly/ga-ruby-on-rails-for-devs/raw/master/images/ga.png "GeneralAssemb.ly") + +#BEWD - Review Lab Session + +###Instructor Name + +--- + + +##Agenda * Review * Lab Time ---- - - +--- + + ##Review ###Request-response ![Request Response Diagram](../../assets/rails/response_request.png) - ---- - - +--- + + + ##Review ###Routes, Views, Controllers and Forms Instructors, you know your class best. What do your students need to review? - + --- - + ##Lab Time ####Ritly @@ -42,13 +42,13 @@ Instructors, you know your class best. What do your students need to review? ####Rewsly 45 min - + --- - -## Homework + +## Homework Complete Rewsly - + --- - + diff --git a/12_Authentication/slides/slides_12.md b/12_Authentication/slides/slides_12.md index 59fe4cf..059c9b8 100644 --- a/12_Authentication/slides/slides_12.md +++ b/12_Authentication/slides/slides_12.md @@ -1,278 +1,278 @@ -![GeneralAssemb.ly](https://github.com/generalassembly/ga-ruby-on-rails-for-devs/raw/master/images/ga.png "GeneralAssemb.ly") - - -https://github.com/plataformatec/devise#getting-started - - -#BEWD - Authentication - -###Instructor Name - - ---- - - -##Agenda - -* Review - * Rewsly Solution - * Rity Solution (Briefly) -* Authentication - * Authentication Explained - * Devise Gem -* Lab - * Authenticated Ritly - ---- - - -##Review -###Rewsly & Ritly - -* Let's review Rewsly solution from last class. -* Since we're going to work on Ritly, let's review that (briefly) as well. - ---- - - -##Authentication - -![GitHub Sign Up Page](../../assets/rails/login_screen.png) - ---- - - -##Authentication - -* Use of a combination of username and password to validate user identity. (Obvious I know…) -* Tracking a user's identity on our app through the __session__. - ---- - -##Authentication -###Security - -![lock image](../../assets/rails/digital_security.jpeg) - ---- - -##Security -* Can I view users' passwords in my app? - -####NO! - ---- - -##Security -###Storing Passwords - -Bad practice to keep passwords in “clear text” - -* Passwords can't be stored in plain text in your database. -If your database is compromised then passwords are compromised as well. - * Don't use the same password for all sites. - ---- - - -##Security -###Hashing - -Use one way hash - -``` -Digest::SHA2.hexdigest("secret") -# => "e5e9fa1ba31ecd1ae84f75caaa474f3a663f05f4" -``` ---- - - -##Security -###Adding Salt - -Salt is random data that are used as an additional input to a one-way function that hashes a password. - - -``` -salt = "a761ce3a45d97e41840a788495e85a70d1bb3815" -password = "secret" -Digest::SHA2.hexdigest(salt+password) -# =>"7963ca00e2e48ea80c615d037494de00a0964682" -``` - ---- - - -##Authentication -###Managing Users - -* When the user is authenticated we store the user_id in the __session__. - ---- - - -##Managing Users -###Session - -* Session data commonly includes the browser user’s identity (name, login, shopping cart, etc.). - -* To work, the web server must uniquely identify each browser’s particular HTTP requests while the session lasts. - -* Commonly, web servers identify browsers by asking them to store a __cookie__. - ---- - -##Managing Users -###Cookie - -* Used to store small bits of information (maximum size about 4k). -* Cookies allow web servers to provide a temporary unique ID to a browser, to enable session management. - * Browser storage is not secure. - * Sensitive data (credit card numbers, etc.) should never be set in a cookie - ---- - - -##Authentication -###Gems -Creating authentication from scratch is a complex process (see resources for more info). However Developers have created Gems to make authentication "easy". - -* __Devise__ -* CanCan -* Clearance -* OmniAuth -* DoorKeeper - ---- - - -##Authentication -###Devise GEM -[https://github.com/plataformatec/devise](https://github.com/plataformatec/devise) - -* Straight-forward to implement, integrate and customize. -* Handles complex security, so you don't have to. -* Provides controller filters and view helpers (more on that in the code along). -* Recently updated (v3.0.0) with Rails 4 support! - - ---- - - - - -##Rewsly - Adding Devise - ---- - - -##Devise -###Recap - -* Adding Devise Gem to the Gemfile - - gem 'devise', '~> 3.0.0' - ---- - - -##Devise -###Recap - -* Using Devise - - rails g devise:install # creates all the devise Controllers, views and initializers - rails g devise user # creates User model (or modifies it if it exists) - rake db:migrate # Let's Go! - - ---- - - -##Devise -###Recap - -* View helpers - - <%= user_is_logged_in? %> - <%= current_user %> - ---- - - -##Authentication -###Recap - -* View helpers - - <%= user_is_logged_in? %> - <%= current_user %> - ---- - -##Devise -###Recap - -* Blocking Access - - class ApplicationController ... - before_action :authenticate_user! - end - - class HomeController < ApplicationController - skip_before_action :authenticate_user! - end - ---- - -##Devise -###Recap - -* Changing the default Route names - - devise_for :users, :path_names => { sign_in: 'login', sign_out: 'logout' } - ---- - - - -##Lab Time - Authenticated Ritly - ---- - - -## Homework - -Write a list of information/data you want to store about your user. - ---- - - -
-## Resources - -###Cheat Sheet - -No cheat sheet this class. Remember, Google is your friend! - - -###Tips, Tricks & Advanced Reading - -* If you want to expand your knowledge about Rails authentication gems visit [Ruby Toolbox](https://www.ruby-toolbox.com/categories/rails_authentication) for a few more authentication gem options. - -* Great [article](http://scientopia.org/blogs/goodmath/2013/03/02/passwords-hashing-and-salt/) explaining passwords, hashing, and salt. - - -* Advanced [article](http://edapx.com/2012/04/18/authorization-and-user-management-in-rails/) about authorization and users management in rails. - -* [Tutorial](http://everydayrails.com/2012/07/31/rails-admin-panel-from-scratch.html) on how to create an advanced admin panel. - -* [Authentication From Scratch](http://railscasts.com/episodes/250-authentication-from-scratch) Rails Cast - - - -###Still Feel Lost? -####Catch Up With These Resources - -* [Devise](http://railscasts.com/episodes/209-introducing-devise) Rails Cast - +![GeneralAssemb.ly](https://github.com/generalassembly/ga-ruby-on-rails-for-devs/raw/master/images/ga.png "GeneralAssemb.ly") + + +https://github.com/plataformatec/devise#getting-started + + +#BEWD - Authentication + +###Instructor Name + + +--- + + +##Agenda + +* Review + * Rewsly Solution + * Rity Solution (Briefly) +* Authentication + * Authentication Explained + * Devise Gem +* Lab + * Authenticated Ritly + +--- + + +##Review +###Rewsly & Ritly + +* Let's review Rewsly solution from last class. +* Since we're going to work on Ritly, let's review that (briefly) as well. + +--- + + +##Authentication + +![GitHub Sign Up Page](../../assets/rails/login_screen.png) + +--- + + +##Authentication + +* Use of a combination of username and password to validate user identity. (Obvious I know…) +* Tracking a user's identity on our app through the __session__. + +--- + +##Authentication +###Security + +![lock image](../../assets/rails/digital_security.jpeg) + +--- + +##Security +* Can I view users' passwords in my app? + +####NO! + +--- + +##Security +###Storing Passwords + +Bad practice to keep passwords in “clear text” + +* Passwords can't be stored in plain text in your database. +If your database is compromised then passwords are compromised as well. + * Don't use the same password for all sites. + +--- + + +##Security +###Hashing + +Use one way hash + +``` +Digest::SHA2.hexdigest("secret") +# => "e5e9fa1ba31ecd1ae84f75caaa474f3a663f05f4" +``` +--- + + +##Security +###Adding Salt + +Salt is random data that are used as an additional input to a one-way function that hashes a password. + + +``` +salt = "a761ce3a45d97e41840a788495e85a70d1bb3815" +password = "secret" +Digest::SHA2.hexdigest(salt+password) +# =>"7963ca00e2e48ea80c615d037494de00a0964682" +``` + +--- + + +##Authentication +###Managing Users + +* When the user is authenticated we store the user_id in the __session__. + +--- + + +##Managing Users +###Session + +* Session data commonly includes the browser user’s identity (name, login, shopping cart, etc.). + +* To work, the web server must uniquely identify each browser’s particular HTTP requests while the session lasts. + +* Commonly, web servers identify browsers by asking them to store a __cookie__. + +--- + +##Managing Users +###Cookie + +* Used to store small bits of information (maximum size about 4k). +* Cookies allow web servers to provide a temporary unique ID to a browser, to enable session management. + * Browser storage is not secure. + * Sensitive data (credit card numbers, etc.) should never be set in a cookie + +--- + + +##Authentication +###Gems +Creating authentication from scratch is a complex process (see resources for more info). However Developers have created Gems to make authentication "easy". + +* __Devise__ +* CanCan +* Clearance +* OmniAuth +* DoorKeeper + +--- + + +##Authentication +###Devise GEM +[https://github.com/plataformatec/devise](https://github.com/plataformatec/devise) + +* Straight-forward to implement, integrate and customize. +* Handles complex security, so you don't have to. +* Provides controller filters and view helpers (more on that in the code along). +* Recently updated (v3.0.0) with Rails 4 support! + + +--- + + + + +##Rewsly - Adding Devise + +--- + + +##Devise +###Recap + +* Adding Devise Gem to the Gemfile + + gem 'devise', '~> 3.0.0' + +--- + + +##Devise +###Recap + +* Using Devise + + rails g devise:install # creates all the devise Controllers, views and initializers + rails g devise user # creates User model (or modifies it if it exists) + rake db:migrate # Let's Go! + + +--- + + +##Devise +###Recap + +* View helpers + + <%= user_is_logged_in? %> + <%= current_user %> + +--- + + +##Authentication +###Recap + +* View helpers + + <%= user_is_logged_in? %> + <%= current_user %> + +--- + +##Devise +###Recap + +* Blocking Access + + class ApplicationController ... + before_action :authenticate_user! + end + + class HomeController < ApplicationController + skip_before_action :authenticate_user! + end + +--- + +##Devise +###Recap + +* Changing the default Route names + + devise_for :users, :path_names => { sign_in: 'login', sign_out: 'logout' } + +--- + + + +##Lab Time - Authenticated Ritly + +--- + + +## Homework + +Write a list of information/data you want to store about your user. + +--- + + +
+## Resources + +###Cheat Sheet + +No cheat sheet this class. Remember, Google is your friend! + + +###Tips, Tricks & Advanced Reading + +* If you want to expand your knowledge about Rails authentication gems visit [Ruby Toolbox](https://www.ruby-toolbox.com/categories/rails_authentication) for a few more authentication gem options. + +* Great [article](http://scientopia.org/blogs/goodmath/2013/03/02/passwords-hashing-and-salt/) explaining passwords, hashing, and salt. + + +* Advanced [article](http://edapx.com/2012/04/18/authorization-and-user-management-in-rails/) about authorization and users management in rails. + +* [Tutorial](http://everydayrails.com/2012/07/31/rails-admin-panel-from-scratch.html) on how to create an advanced admin panel. + +* [Authentication From Scratch](http://railscasts.com/episodes/250-authentication-from-scratch) Rails Cast + + + +###Still Feel Lost? +####Catch Up With These Resources + +* [Devise](http://railscasts.com/episodes/209-introducing-devise) Rails Cast + From 0a894743c145f8686a6ea8654da748c264e88b70 Mon Sep 17 00:00:00 2001 From: Paul Mumma Date: Tue, 20 May 2014 20:43:33 -0700 Subject: [PATCH 03/14] committing again --- blog.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blog.txt b/blog.txt index 2f572cd..cae8047 100644 --- a/blog.txt +++ b/blog.txt @@ -3,4 +3,4 @@ Paul's blog post == Name: Paul Mumma -URL: www.paulmumma.com/blog \ No newline at end of file +URL: www.paulmumma.com \ No newline at end of file From 691054947c08699457f450e77b63dfd91b8fde8e Mon Sep 17 00:00:00 2001 From: Paul Mumma Date: Thu, 5 Jun 2014 18:00:20 -0700 Subject: [PATCH 04/14] Thursday commit --- .../starter_code/code_demo_apartment.rb | 41 ++++++++ apartment.rb | 12 +++ building.rb | 10 ++ person.rb | 9 ++ week 3 lab/lib/apartment.rb | 25 +++++ week 3 lab/lib/building.rb | 18 ++++ week 3 lab/lib/person.rb | 9 ++ week 3 lab/main.rb | 93 +++++++++++++++++++ week3.rb | 65 +++++++++++++ 9 files changed, 282 insertions(+) create mode 100644 apartment.rb create mode 100644 building.rb create mode 100644 person.rb create mode 100644 week 3 lab/lib/apartment.rb create mode 100644 week 3 lab/lib/building.rb create mode 100644 week 3 lab/lib/person.rb create mode 100644 week 3 lab/main.rb create mode 100644 week3.rb diff --git a/05_Classes_Objects/starter_code/code_demo_apartment.rb b/05_Classes_Objects/starter_code/code_demo_apartment.rb index 287c011..b525c52 100644 --- a/05_Classes_Objects/starter_code/code_demo_apartment.rb +++ b/05_Classes_Objects/starter_code/code_demo_apartment.rb @@ -3,5 +3,46 @@ class Apartment + attr_accessor :name, :rent, :sq_footage, :num_b, :renters + def initialize(name, rent, sq_footage,num_b) + @name = name + @rent = rent + @sq_footage = sq_footage + @num_b = num_b + @renters = [] + end + + def is_occupied? + @renters.any? + end + + def to_s + puts "#{@name} has #{@sq_footage} square feet, #{@num_b} bedrooms and costs $#{@rent} per month" + end + + #this might be wrong! + def add_renters(renters_name) + @renters << renters_name + end + + def delete_renters(renters_name) + @renters.delete(renters_name) +end + +my_apartment = Apartment.new("SF SOMA", 2000, 800, 1) +kirstens_apartment = Apartment.new("Burlingame Studio", 1500, 450, 0) +pauls_apartment = Apartment.new("Millbrae 2 BR", 1800, 800, 2) + +if my_apartment.is_occupied? + puts "This apartment is not for rent" +else + puts my_apartment + puts "This apartment is for rent" +end + +my_apartment.renters = ["Paul","Greg"] +puts my_apartment.renters +my_apartment.delete_renters("Paul") +puts my_apartment.renters end \ No newline at end of file diff --git a/apartment.rb b/apartment.rb new file mode 100644 index 0000000..339f873 --- /dev/null +++ b/apartment.rb @@ -0,0 +1,12 @@ +class Apartment + + attr_accessor :name, :apt_sqft, :apt_bedrooms, :apt_bathrooms + + def initialize(name, apt_sqft, apt_bedrooms, apt_bathrooms) + @name = name + @apt_sqft = apt_sqft + @apt_bedrooms = apt_bedrooms + @apt_bathrooms = apt_bathrooms + end + +end \ No newline at end of file diff --git a/building.rb b/building.rb new file mode 100644 index 0000000..7b9ed27 --- /dev/null +++ b/building.rb @@ -0,0 +1,10 @@ +class Building + + attr_accessor :building_name, :building_address + + def initialize(building_name, building_address) + @building_name = building_name + @building_address = building_address + end + +end \ No newline at end of file diff --git a/person.rb b/person.rb new file mode 100644 index 0000000..cc19843 --- /dev/null +++ b/person.rb @@ -0,0 +1,9 @@ +class Renter + attr_accessor :name, :credit_score, :gender + + def initialize (name, credit_score, gender) + @name = name + @credit_score = credit_score + @gender = gender + end +end diff --git a/week 3 lab/lib/apartment.rb b/week 3 lab/lib/apartment.rb new file mode 100644 index 0000000..47ad36e --- /dev/null +++ b/week 3 lab/lib/apartment.rb @@ -0,0 +1,25 @@ +class Apartment + + attr_accessor :name, :apt_sqft, :apt_bedrooms, :apt_bathrooms, :renter, :rent + + def initialize(name, apt_sqft, apt_bedrooms, apt_bathrooms) + @name = name + @apt_sqft = apt_sqft + @apt_bedrooms = apt_bedrooms + @apt_bathrooms = apt_bathrooms + @renter = nil + @rent = nil + end + +def is_rented? + @renter !=nil +end + + + def to_s + "Apartment: #{name} +Sqft: #{apt_sqft} Bedrooms: #{apt_bedrooms} Bathrooms: #{apt_bathrooms} +" + end + +end diff --git a/week 3 lab/lib/building.rb b/week 3 lab/lib/building.rb new file mode 100644 index 0000000..5dabc04 --- /dev/null +++ b/week 3 lab/lib/building.rb @@ -0,0 +1,18 @@ +class Building + + attr_accessor :building_name, :building_address, :apartments + + def initialize(building_name, building_address) + @building_name = building_name + @building_address = building_address + @apartments = [] + end + + def view_apartments + puts "-----------Full Apartments List-----------" + @apartments.each do |apartment| + puts apartment + end + end + +end \ No newline at end of file diff --git a/week 3 lab/lib/person.rb b/week 3 lab/lib/person.rb new file mode 100644 index 0000000..2d18873 --- /dev/null +++ b/week 3 lab/lib/person.rb @@ -0,0 +1,9 @@ +class Person + attr_accessor :name, :credit_score, :gender + + def initialize (name, credit_score, gender) + @name = name + @credit_score = credit_score + @gender = gender + end +end diff --git a/week 3 lab/main.rb b/week 3 lab/main.rb new file mode 100644 index 0000000..1f5b1ab --- /dev/null +++ b/week 3 lab/main.rb @@ -0,0 +1,93 @@ +# Exercise Goal: This is an exercise in reading and writing code. +# => The purpose of this exercise is to practice creating classes. +# Task Instructions: +# => The main.rb file is where the application starts, and we've given you the code below. +# => Your job is to write the "Apartment", "Building" and "Person" classes. +# => Read the code below and use it to inform what variables and methods are necessary for each of the classes listed above. +# => We've also provided a png file of the terminal output from the completed version. +# => Hint: Think before you code. Annotate code and comment out sections as you test different sections + +require_relative 'lib/building' +require_relative 'lib/apartment' +require_relative 'lib/person' + +## First, define our methods + +def create_apartment + puts "-----------New Apartment-----------" + puts "What is the apartment number / name?" + name = gets.strip + + puts "How many square feet is apartment #{name}?" + apt_sqft = gets.to_i + + puts "How many bedrooms does apartment #{name} have?" + apt_bedrooms = gets.to_i + + puts "How many bathrooms does apartment #{name} have?" + apt_bathrooms = gets.to_i + + Apartment.new(name, apt_sqft, apt_bedrooms, apt_bathrooms) +end + +def create_renter + puts "-----------New Renter-----------" + puts "What is the renter's name?" + name = gets.strip + + puts "What is the #{name}'s credit score?" + credit_score = gets.to_i + + puts "Is #{name} male or female?" + gender = gets.strip + + Person.new(name, credit_score, gender) +end + +def create_building + puts "-----------New Building-----------" + puts "What is the building's name?" + building_name = gets.strip + + puts "What is the building's address?" + building_address = gets.strip + + Building.new(building_name, building_address) +end + +# Now call methods to run the program + +puts "******************Welcome to Ruby Building Manager****************** \n \n \n" + +building = create_building + +puts "How many units are there?" +apt_count = gets.to_i + + 0.upto(apt_count - 1) do |unit| + apartment = create_apartment + building.apartments[unit] = apartment + + puts "Apartment added successfully \n #{apartment}" + + puts "Is unit #{apartment.name} rented? (y)es (n)o" + unit_rented = gets.strip + + if unit_rented == "y" + apartment.renter = create_renter + puts "Renter added successfully" + + puts "How much is this unit rented for?" + rent = gets.to_i + apartment.rent = rent + end +end + +puts "What would you like to do next, (v)iew all apartments? (q)uit?" +response = gets.strip + +if response == 'v' + building.view_apartments +else + puts "Thanks for using Ruby Building Manager" +end \ No newline at end of file diff --git a/week3.rb b/week3.rb new file mode 100644 index 0000000..e5de92d --- /dev/null +++ b/week3.rb @@ -0,0 +1,65 @@ +# jimmy ={} +# jimmy[:name] = "Jimmy J" +# jimmy[:major] = "Math" +# jimmy[:course] = "Math" +# jimmy[:grade] = "A" + +# ed ={} +# ed[:name] = "Eddy E" +# ed[:major] = "English" +# ed[:course] = "Math" +# ed[:grade] = "C" + +# ted ={} +# ted[:name] = "Teddy T" +# ted[:major] = "Math" +# ted[:course] = "English" +# ted[:grade] = "A" + + +class Student + attr_accessor :name, :major, :course, :grade + + def initialize(n, major, course, grade) + @name = n + @major = major + @course = course + @grade = grade + end + + def grade_status + if @grade == "F" + "failed" + elsif ["D", "E"].include?(@grade) && @major == @course + "failed" + else + "passed" + end + end + + def compare(other_student) + + end + + def to_s + puts "#{@name} has #{grade_status} #{@course}" + end +end + +# jimmy = Student.new +# jimmy.name = "Jimmy J" +# jimmy.major = "Math" +# jimmy.course = "Math" +# jimmy.grade = "A" + +# ed = Student.new +# ed.name = "Ed D" +# ed.major = "English" +# ed.course = "Math" +# ed.grade = "D" + +tom = Student.new("tom","classics","math","F") + +# puts "#{jimmy.name} has #{jimmy.grade_status} #{jimmy.course}" +# puts "#{ed.name} has #{ed.grade_status} #{ed.course}" +puts tom \ No newline at end of file From cf2b645dd4bc301f7395cfe8ba0338146628b688 Mon Sep 17 00:00:00 2001 From: Paul Mumma Date: Tue, 10 Jun 2014 20:22:08 -0700 Subject: [PATCH 05/14] rails --- Wk 3/APILab | 0 Wk 3/APILab.rb | 0 Wk 3/OOSN.rb | 22 +++ Wk 3/SnLab/SecretNumber.rb | 20 +++ Wk 3/SnLab/game.rb | 9 ++ Wk 3/SnLab/main.rb | 13 ++ Wk 3/SnLab/player.rb | 8 ++ Wk 3/ThursClass.rb | 127 ++++++++++++++++++ Wk 3/week 3 lab/lib/apartment.rb | 25 ++++ Wk 3/week 3 lab/lib/building.rb | 31 +++++ Wk 3/week 3 lab/lib/person.rb | 14 ++ Wk 3/week 3 lab/main.rb | 95 +++++++++++++ Wk 3/week3.rb | 65 +++++++++ wk4/User_Scaffold/.gitignore | 16 +++ wk4/User_Scaffold/Gemfile | 40 ++++++ wk4/User_Scaffold/Gemfile.lock | 125 +++++++++++++++++ wk4/User_Scaffold/README.rdoc | 28 ++++ wk4/User_Scaffold/Rakefile | 6 + wk4/User_Scaffold/app/assets/images/.keep | 0 .../app/assets/javascripts/application.js | 16 +++ .../app/assets/javascripts/users.js.coffee | 3 + .../app/assets/stylesheets/application.css | 15 +++ .../app/assets/stylesheets/scaffolds.css.scss | 69 ++++++++++ .../app/assets/stylesheets/users.css.scss | 3 + .../app/controllers/application_controller.rb | 5 + .../app/controllers/concerns/.keep | 0 .../app/controllers/users_controller.rb | 74 ++++++++++ .../app/helpers/application_helper.rb | 2 + wk4/User_Scaffold/app/helpers/users_helper.rb | 2 + wk4/User_Scaffold/app/mailers/.keep | 0 wk4/User_Scaffold/app/models/.keep | 0 wk4/User_Scaffold/app/models/concerns/.keep | 0 wk4/User_Scaffold/app/models/user.rb | 2 + .../app/views/layouts/application.html.erb | 14 ++ .../app/views/users/_form.html.erb | 33 +++++ .../app/views/users/edit.html.erb | 6 + .../app/views/users/index.html.erb | 31 +++++ .../app/views/users/index.json.jbuilder | 4 + .../app/views/users/new.html.erb | 5 + .../app/views/users/show.html.erb | 24 ++++ .../app/views/users/show.json.jbuilder | 1 + wk4/User_Scaffold/bin/bundle | 3 + wk4/User_Scaffold/bin/rails | 8 ++ wk4/User_Scaffold/bin/rake | 8 ++ wk4/User_Scaffold/bin/spring | 18 +++ wk4/User_Scaffold/config.ru | 4 + wk4/User_Scaffold/config/application.rb | 23 ++++ wk4/User_Scaffold/config/boot.rb | 4 + wk4/User_Scaffold/config/database.yml | 25 ++++ wk4/User_Scaffold/config/environment.rb | 5 + .../config/environments/development.rb | 37 +++++ .../config/environments/production.rb | 83 ++++++++++++ wk4/User_Scaffold/config/environments/test.rb | 39 ++++++ .../initializers/backtrace_silencers.rb | 7 + .../config/initializers/cookies_serializer.rb | 3 + .../initializers/filter_parameter_logging.rb | 4 + .../config/initializers/inflections.rb | 16 +++ .../config/initializers/mime_types.rb | 4 + .../config/initializers/session_store.rb | 3 + .../config/initializers/wrap_parameters.rb | 14 ++ wk4/User_Scaffold/config/locales/en.yml | 23 ++++ wk4/User_Scaffold/config/routes.rb | 58 ++++++++ wk4/User_Scaffold/config/secrets.yml | 22 +++ .../db/migrate/20140611025626_create_users.rb | 12 ++ wk4/User_Scaffold/db/schema.rb | 25 ++++ wk4/User_Scaffold/db/seeds.rb | 7 + wk4/User_Scaffold/lib/assets/.keep | 0 wk4/User_Scaffold/lib/tasks/.keep | 0 wk4/User_Scaffold/log/.keep | 0 wk4/User_Scaffold/public/404.html | 67 +++++++++ wk4/User_Scaffold/public/422.html | 67 +++++++++ wk4/User_Scaffold/public/500.html | 66 +++++++++ wk4/User_Scaffold/public/favicon.ico | 0 wk4/User_Scaffold/public/robots.txt | 5 + wk4/User_Scaffold/test/controllers/.keep | 0 .../test/controllers/users_controller_test.rb | 49 +++++++ wk4/User_Scaffold/test/fixtures/.keep | 0 wk4/User_Scaffold/test/fixtures/users.yml | 13 ++ wk4/User_Scaffold/test/helpers/.keep | 0 .../test/helpers/users_helper_test.rb | 4 + wk4/User_Scaffold/test/integration/.keep | 0 wk4/User_Scaffold/test/mailers/.keep | 0 wk4/User_Scaffold/test/models/.keep | 0 wk4/User_Scaffold/test/models/user_test.rb | 7 + wk4/User_Scaffold/test/test_helper.rb | 13 ++ .../vendor/assets/javascripts/.keep | 0 .../vendor/assets/stylesheets/.keep | 0 wk4/my_new_app/.gitignore | 16 +++ wk4/my_new_app/Gemfile | 40 ++++++ wk4/my_new_app/Gemfile.lock | 125 +++++++++++++++++ wk4/my_new_app/README.rdoc | 28 ++++ wk4/my_new_app/Rakefile | 6 + wk4/my_new_app/app/assets/images/.keep | 0 .../app/assets/javascripts/application.js | 16 +++ .../app/assets/javascripts/books.js.coffee | 3 + .../app/assets/stylesheets/application.css | 15 +++ .../app/assets/stylesheets/books.css.scss | 3 + .../app/assets/stylesheets/scaffolds.css.scss | 69 ++++++++++ .../app/controllers/application_controller.rb | 5 + .../app/controllers/books_controller.rb | 74 ++++++++++ wk4/my_new_app/app/controllers/concerns/.keep | 0 .../app/helpers/application_helper.rb | 2 + wk4/my_new_app/app/helpers/books_helper.rb | 2 + wk4/my_new_app/app/mailers/.keep | 0 wk4/my_new_app/app/models/.keep | 0 wk4/my_new_app/app/models/book.rb | 2 + wk4/my_new_app/app/models/concerns/.keep | 0 wk4/my_new_app/app/views/books/_form.html.erb | 29 ++++ wk4/my_new_app/app/views/books/edit.html.erb | 6 + wk4/my_new_app/app/views/books/index.html.erb | 29 ++++ .../app/views/books/index.json.jbuilder | 4 + wk4/my_new_app/app/views/books/new.html.erb | 5 + wk4/my_new_app/app/views/books/show.html.erb | 19 +++ .../app/views/books/show.json.jbuilder | 1 + .../app/views/layouts/application.html.erb | 14 ++ wk4/my_new_app/bin/bundle | 3 + wk4/my_new_app/bin/rails | 8 ++ wk4/my_new_app/bin/rake | 8 ++ wk4/my_new_app/bin/spring | 18 +++ wk4/my_new_app/config.rb | 0 wk4/my_new_app/config.ru | 4 + wk4/my_new_app/config/application.rb | 23 ++++ wk4/my_new_app/config/boot.rb | 4 + wk4/my_new_app/config/database.yml | 25 ++++ wk4/my_new_app/config/environment.rb | 5 + .../config/environments/development.rb | 37 +++++ .../config/environments/production.rb | 83 ++++++++++++ wk4/my_new_app/config/environments/test.rb | 39 ++++++ .../initializers/backtrace_silencers.rb | 7 + .../config/initializers/cookies_serializer.rb | 3 + .../initializers/filter_parameter_logging.rb | 4 + .../config/initializers/inflections.rb | 16 +++ .../config/initializers/mime_types.rb | 4 + .../config/initializers/session_store.rb | 3 + .../config/initializers/wrap_parameters.rb | 14 ++ wk4/my_new_app/config/locales/en.yml | 23 ++++ wk4/my_new_app/config/routes.rb | 58 ++++++++ wk4/my_new_app/config/secrets.yml | 22 +++ .../db/migrate/20140611014121_create_books.rb | 11 ++ wk4/my_new_app/db/schema.rb | 24 ++++ wk4/my_new_app/db/seeds.rb | 7 + wk4/my_new_app/lib/assets/.keep | 0 wk4/my_new_app/lib/tasks/.keep | 0 wk4/my_new_app/log/.keep | 0 wk4/my_new_app/public/404.html | 67 +++++++++ wk4/my_new_app/public/422.html | 67 +++++++++ wk4/my_new_app/public/500.html | 66 +++++++++ wk4/my_new_app/public/favicon.ico | 0 wk4/my_new_app/public/robots.txt | 5 + wk4/my_new_app/public/testing.txt | 1 + wk4/my_new_app/test/controllers/.keep | 0 .../test/controllers/books_controller_test.rb | 49 +++++++ wk4/my_new_app/test/fixtures/.keep | 0 wk4/my_new_app/test/fixtures/books.yml | 11 ++ wk4/my_new_app/test/helpers/.keep | 0 .../test/helpers/books_helper_test.rb | 4 + wk4/my_new_app/test/integration/.keep | 0 wk4/my_new_app/test/mailers/.keep | 0 wk4/my_new_app/test/models/.keep | 0 wk4/my_new_app/test/models/book_test.rb | 7 + wk4/my_new_app/test/test_helper.rb | 13 ++ .../vendor/assets/javascripts/.keep | 0 .../vendor/assets/stylesheets/.keep | 0 wk4/tuesday | 0 164 files changed, 2955 insertions(+) create mode 100644 Wk 3/APILab create mode 100644 Wk 3/APILab.rb create mode 100644 Wk 3/OOSN.rb create mode 100644 Wk 3/SnLab/SecretNumber.rb create mode 100644 Wk 3/SnLab/game.rb create mode 100644 Wk 3/SnLab/main.rb create mode 100644 Wk 3/SnLab/player.rb create mode 100644 Wk 3/ThursClass.rb create mode 100644 Wk 3/week 3 lab/lib/apartment.rb create mode 100644 Wk 3/week 3 lab/lib/building.rb create mode 100644 Wk 3/week 3 lab/lib/person.rb create mode 100644 Wk 3/week 3 lab/main.rb create mode 100644 Wk 3/week3.rb create mode 100644 wk4/User_Scaffold/.gitignore create mode 100644 wk4/User_Scaffold/Gemfile create mode 100644 wk4/User_Scaffold/Gemfile.lock create mode 100644 wk4/User_Scaffold/README.rdoc create mode 100644 wk4/User_Scaffold/Rakefile create mode 100644 wk4/User_Scaffold/app/assets/images/.keep create mode 100644 wk4/User_Scaffold/app/assets/javascripts/application.js create mode 100644 wk4/User_Scaffold/app/assets/javascripts/users.js.coffee create mode 100644 wk4/User_Scaffold/app/assets/stylesheets/application.css create mode 100644 wk4/User_Scaffold/app/assets/stylesheets/scaffolds.css.scss create mode 100644 wk4/User_Scaffold/app/assets/stylesheets/users.css.scss create mode 100644 wk4/User_Scaffold/app/controllers/application_controller.rb create mode 100644 wk4/User_Scaffold/app/controllers/concerns/.keep create mode 100644 wk4/User_Scaffold/app/controllers/users_controller.rb create mode 100644 wk4/User_Scaffold/app/helpers/application_helper.rb create mode 100644 wk4/User_Scaffold/app/helpers/users_helper.rb create mode 100644 wk4/User_Scaffold/app/mailers/.keep create mode 100644 wk4/User_Scaffold/app/models/.keep create mode 100644 wk4/User_Scaffold/app/models/concerns/.keep create mode 100644 wk4/User_Scaffold/app/models/user.rb create mode 100644 wk4/User_Scaffold/app/views/layouts/application.html.erb create mode 100644 wk4/User_Scaffold/app/views/users/_form.html.erb create mode 100644 wk4/User_Scaffold/app/views/users/edit.html.erb create mode 100644 wk4/User_Scaffold/app/views/users/index.html.erb create mode 100644 wk4/User_Scaffold/app/views/users/index.json.jbuilder create mode 100644 wk4/User_Scaffold/app/views/users/new.html.erb create mode 100644 wk4/User_Scaffold/app/views/users/show.html.erb create mode 100644 wk4/User_Scaffold/app/views/users/show.json.jbuilder create mode 100755 wk4/User_Scaffold/bin/bundle create mode 100755 wk4/User_Scaffold/bin/rails create mode 100755 wk4/User_Scaffold/bin/rake create mode 100755 wk4/User_Scaffold/bin/spring create mode 100644 wk4/User_Scaffold/config.ru create mode 100644 wk4/User_Scaffold/config/application.rb create mode 100644 wk4/User_Scaffold/config/boot.rb create mode 100644 wk4/User_Scaffold/config/database.yml create mode 100644 wk4/User_Scaffold/config/environment.rb create mode 100644 wk4/User_Scaffold/config/environments/development.rb create mode 100644 wk4/User_Scaffold/config/environments/production.rb create mode 100644 wk4/User_Scaffold/config/environments/test.rb create mode 100644 wk4/User_Scaffold/config/initializers/backtrace_silencers.rb create mode 100644 wk4/User_Scaffold/config/initializers/cookies_serializer.rb create mode 100644 wk4/User_Scaffold/config/initializers/filter_parameter_logging.rb create mode 100644 wk4/User_Scaffold/config/initializers/inflections.rb create mode 100644 wk4/User_Scaffold/config/initializers/mime_types.rb create mode 100644 wk4/User_Scaffold/config/initializers/session_store.rb create mode 100644 wk4/User_Scaffold/config/initializers/wrap_parameters.rb create mode 100644 wk4/User_Scaffold/config/locales/en.yml create mode 100644 wk4/User_Scaffold/config/routes.rb create mode 100644 wk4/User_Scaffold/config/secrets.yml create mode 100644 wk4/User_Scaffold/db/migrate/20140611025626_create_users.rb create mode 100644 wk4/User_Scaffold/db/schema.rb create mode 100644 wk4/User_Scaffold/db/seeds.rb create mode 100644 wk4/User_Scaffold/lib/assets/.keep create mode 100644 wk4/User_Scaffold/lib/tasks/.keep create mode 100644 wk4/User_Scaffold/log/.keep create mode 100644 wk4/User_Scaffold/public/404.html create mode 100644 wk4/User_Scaffold/public/422.html create mode 100644 wk4/User_Scaffold/public/500.html create mode 100644 wk4/User_Scaffold/public/favicon.ico create mode 100644 wk4/User_Scaffold/public/robots.txt create mode 100644 wk4/User_Scaffold/test/controllers/.keep create mode 100644 wk4/User_Scaffold/test/controllers/users_controller_test.rb create mode 100644 wk4/User_Scaffold/test/fixtures/.keep create mode 100644 wk4/User_Scaffold/test/fixtures/users.yml create mode 100644 wk4/User_Scaffold/test/helpers/.keep create mode 100644 wk4/User_Scaffold/test/helpers/users_helper_test.rb create mode 100644 wk4/User_Scaffold/test/integration/.keep create mode 100644 wk4/User_Scaffold/test/mailers/.keep create mode 100644 wk4/User_Scaffold/test/models/.keep create mode 100644 wk4/User_Scaffold/test/models/user_test.rb create mode 100644 wk4/User_Scaffold/test/test_helper.rb create mode 100644 wk4/User_Scaffold/vendor/assets/javascripts/.keep create mode 100644 wk4/User_Scaffold/vendor/assets/stylesheets/.keep create mode 100644 wk4/my_new_app/.gitignore create mode 100644 wk4/my_new_app/Gemfile create mode 100644 wk4/my_new_app/Gemfile.lock create mode 100644 wk4/my_new_app/README.rdoc create mode 100644 wk4/my_new_app/Rakefile create mode 100644 wk4/my_new_app/app/assets/images/.keep create mode 100644 wk4/my_new_app/app/assets/javascripts/application.js create mode 100644 wk4/my_new_app/app/assets/javascripts/books.js.coffee create mode 100644 wk4/my_new_app/app/assets/stylesheets/application.css create mode 100644 wk4/my_new_app/app/assets/stylesheets/books.css.scss create mode 100644 wk4/my_new_app/app/assets/stylesheets/scaffolds.css.scss create mode 100644 wk4/my_new_app/app/controllers/application_controller.rb create mode 100644 wk4/my_new_app/app/controllers/books_controller.rb create mode 100644 wk4/my_new_app/app/controllers/concerns/.keep create mode 100644 wk4/my_new_app/app/helpers/application_helper.rb create mode 100644 wk4/my_new_app/app/helpers/books_helper.rb create mode 100644 wk4/my_new_app/app/mailers/.keep create mode 100644 wk4/my_new_app/app/models/.keep create mode 100644 wk4/my_new_app/app/models/book.rb create mode 100644 wk4/my_new_app/app/models/concerns/.keep create mode 100644 wk4/my_new_app/app/views/books/_form.html.erb create mode 100644 wk4/my_new_app/app/views/books/edit.html.erb create mode 100644 wk4/my_new_app/app/views/books/index.html.erb create mode 100644 wk4/my_new_app/app/views/books/index.json.jbuilder create mode 100644 wk4/my_new_app/app/views/books/new.html.erb create mode 100644 wk4/my_new_app/app/views/books/show.html.erb create mode 100644 wk4/my_new_app/app/views/books/show.json.jbuilder create mode 100644 wk4/my_new_app/app/views/layouts/application.html.erb create mode 100755 wk4/my_new_app/bin/bundle create mode 100755 wk4/my_new_app/bin/rails create mode 100755 wk4/my_new_app/bin/rake create mode 100755 wk4/my_new_app/bin/spring create mode 100644 wk4/my_new_app/config.rb create mode 100644 wk4/my_new_app/config.ru create mode 100644 wk4/my_new_app/config/application.rb create mode 100644 wk4/my_new_app/config/boot.rb create mode 100644 wk4/my_new_app/config/database.yml create mode 100644 wk4/my_new_app/config/environment.rb create mode 100644 wk4/my_new_app/config/environments/development.rb create mode 100644 wk4/my_new_app/config/environments/production.rb create mode 100644 wk4/my_new_app/config/environments/test.rb create mode 100644 wk4/my_new_app/config/initializers/backtrace_silencers.rb create mode 100644 wk4/my_new_app/config/initializers/cookies_serializer.rb create mode 100644 wk4/my_new_app/config/initializers/filter_parameter_logging.rb create mode 100644 wk4/my_new_app/config/initializers/inflections.rb create mode 100644 wk4/my_new_app/config/initializers/mime_types.rb create mode 100644 wk4/my_new_app/config/initializers/session_store.rb create mode 100644 wk4/my_new_app/config/initializers/wrap_parameters.rb create mode 100644 wk4/my_new_app/config/locales/en.yml create mode 100644 wk4/my_new_app/config/routes.rb create mode 100644 wk4/my_new_app/config/secrets.yml create mode 100644 wk4/my_new_app/db/migrate/20140611014121_create_books.rb create mode 100644 wk4/my_new_app/db/schema.rb create mode 100644 wk4/my_new_app/db/seeds.rb create mode 100644 wk4/my_new_app/lib/assets/.keep create mode 100644 wk4/my_new_app/lib/tasks/.keep create mode 100644 wk4/my_new_app/log/.keep create mode 100644 wk4/my_new_app/public/404.html create mode 100644 wk4/my_new_app/public/422.html create mode 100644 wk4/my_new_app/public/500.html create mode 100644 wk4/my_new_app/public/favicon.ico create mode 100644 wk4/my_new_app/public/robots.txt create mode 100644 wk4/my_new_app/public/testing.txt create mode 100644 wk4/my_new_app/test/controllers/.keep create mode 100644 wk4/my_new_app/test/controllers/books_controller_test.rb create mode 100644 wk4/my_new_app/test/fixtures/.keep create mode 100644 wk4/my_new_app/test/fixtures/books.yml create mode 100644 wk4/my_new_app/test/helpers/.keep create mode 100644 wk4/my_new_app/test/helpers/books_helper_test.rb create mode 100644 wk4/my_new_app/test/integration/.keep create mode 100644 wk4/my_new_app/test/mailers/.keep create mode 100644 wk4/my_new_app/test/models/.keep create mode 100644 wk4/my_new_app/test/models/book_test.rb create mode 100644 wk4/my_new_app/test/test_helper.rb create mode 100644 wk4/my_new_app/vendor/assets/javascripts/.keep create mode 100644 wk4/my_new_app/vendor/assets/stylesheets/.keep create mode 100644 wk4/tuesday diff --git a/Wk 3/APILab b/Wk 3/APILab new file mode 100644 index 0000000..e69de29 diff --git a/Wk 3/APILab.rb b/Wk 3/APILab.rb new file mode 100644 index 0000000..e69de29 diff --git a/Wk 3/OOSN.rb b/Wk 3/OOSN.rb new file mode 100644 index 0000000..2c29f16 --- /dev/null +++ b/Wk 3/OOSN.rb @@ -0,0 +1,22 @@ +class Main +puts "\nWelcome to the Secret Number Game!" + +first_name = "Paul" +last_name = "Mumma" + +puts "Created by " + first_name + " " + last_name + +puts "\nWhat is your name?" + +player_name = $stdin.gets.chomp + +end + +# class SecretNumber +# end + +# class Player +# end + +# class Game +# end diff --git a/Wk 3/SnLab/SecretNumber.rb b/Wk 3/SnLab/SecretNumber.rb new file mode 100644 index 0000000..6693c8e --- /dev/null +++ b/Wk 3/SnLab/SecretNumber.rb @@ -0,0 +1,20 @@ +# Initialize class +# set pool of 10 numbers +# choose 1 double-blind secret number + +class SecretNumber +attr_accessor :secret_number + def initialize + @secret_number = [] + end + + def set_array + + end + + def choose_secret + new.secret + end + + +end \ No newline at end of file diff --git a/Wk 3/SnLab/game.rb b/Wk 3/SnLab/game.rb new file mode 100644 index 0000000..1a21a56 --- /dev/null +++ b/Wk 3/SnLab/game.rb @@ -0,0 +1,9 @@ +require 'lib/person' +require 'lib/secret_number' + +class Game +# this class will be complex +# we need to write logic to initialize a new game, and run the game loop +# we'll want to write a few separate methods for unique tasks so that our +# code is structured properly +end diff --git a/Wk 3/SnLab/main.rb b/Wk 3/SnLab/main.rb new file mode 100644 index 0000000..445e3b7 --- /dev/null +++ b/Wk 3/SnLab/main.rb @@ -0,0 +1,13 @@ +#Welcome user to game +puts "\nWelcome to the Secret Number Game!" + +#Tell user who created the game +first_name = "Paul" +last_name = "Mumma" + +puts "Created by " + first_name + " " + last_name + +puts "\nWhat is your name?" + +player_name = $stdin.gets.chomp + diff --git a/Wk 3/SnLab/player.rb b/Wk 3/SnLab/player.rb new file mode 100644 index 0000000..44778f8 --- /dev/null +++ b/Wk 3/SnLab/player.rb @@ -0,0 +1,8 @@ +class Player +attr_accessor :name + def initialize + @name = name + end +end + +player = Player.new(player_name) diff --git a/Wk 3/ThursClass.rb b/Wk 3/ThursClass.rb new file mode 100644 index 0000000..1301850 --- /dev/null +++ b/Wk 3/ThursClass.rb @@ -0,0 +1,127 @@ +# # class NewsPaper +# # attr_accessor :stories + +# # def initialize +# # @stories = [] +# # end + +# # def self.generate_random_story +# # "This random even happened on day #{rand(28)} of this month" +# # end + +# # def add_story(story) +# # self.stories << storyend +# # end + +# # end + +# # story = NewsPaper.generate_random_story +# # puts story + +# # paper = NewsPaper.new +# # paper.add.story(story) +# # puts + +# # class GA_course +# # attr_accessor :course_name +# # def initialize(course_name) +# # @course_name = course_name +# # end + +# # def announce_course +# # puts "GA is offering a course called #{course_name} right now!" +# # end + +# # def self.announce_all_courses +# # puts "GA offers lots of wacky stuff" +# # end + +# # end + +# # our_course = GA_course.new("BEWD") +# # our_course.announce_course +# # GA_course.announce_all_courses + +# class Employee +# attr_accessor :first_name, :last_name + +# def initialize(first_name, last_name) +# @first_name = first_name +# @last_name = last_name +# end + +# def full_name +# "#{first_name} #{last_name}" +# end +# end + +# mari=Employee.new("Mari", "Miyachi") +# puts mari.full_name + +# class Manager < Employee +# attr_accessor :email_address, :title + +# def initialize(first_name, last_name, email_address, title) +# # @first_name=first_name +# # @last_name = last_name +# super(first_name, last_name) +# @email_address = email_address +# @title = title +# end + +# def full_name +# "#{@first_name} #{@last_name} #{@title}" +# end + +# def contact +# "#{@email_address}" +# end +# end + + +# class Marketer < Employee +# attr_accessor :twitter_name + +# def initialize(first_name, last_name, twitter_name) +# super(first_name, last_name) +# @twitter_name=twitter_name +# end + +# def contact +# "#{@twitter_name}" +# end +# end + +# class AssistantMarketer < Marketer + +# end + + +# jane=Manager.new("Jane", "Jacobcs", "mari@yahoo", "Bucho") +# puts jane.full_name + +# puts jane.contact + +# ted = Marketer.new("Ted", "e", "teddSauce") + +# puts ted.contact + +module Animal + class Bat + def fly! + puts "go fly!!" + end + end +end + +module Blunt_instruments + class Bat + def made_of + "wood" + end + end +end + +Animal::Bat.new +Blunt_instruments::Bat.new + diff --git a/Wk 3/week 3 lab/lib/apartment.rb b/Wk 3/week 3 lab/lib/apartment.rb new file mode 100644 index 0000000..47ad36e --- /dev/null +++ b/Wk 3/week 3 lab/lib/apartment.rb @@ -0,0 +1,25 @@ +class Apartment + + attr_accessor :name, :apt_sqft, :apt_bedrooms, :apt_bathrooms, :renter, :rent + + def initialize(name, apt_sqft, apt_bedrooms, apt_bathrooms) + @name = name + @apt_sqft = apt_sqft + @apt_bedrooms = apt_bedrooms + @apt_bathrooms = apt_bathrooms + @renter = nil + @rent = nil + end + +def is_rented? + @renter !=nil +end + + + def to_s + "Apartment: #{name} +Sqft: #{apt_sqft} Bedrooms: #{apt_bedrooms} Bathrooms: #{apt_bathrooms} +" + end + +end diff --git a/Wk 3/week 3 lab/lib/building.rb b/Wk 3/week 3 lab/lib/building.rb new file mode 100644 index 0000000..ac6d1d5 --- /dev/null +++ b/Wk 3/week 3 lab/lib/building.rb @@ -0,0 +1,31 @@ +class Building + + attr_accessor :building_name, :building_address, :apartments + + def initialize(building_name, building_address) + @building_name = building_name + @building_address = building_address + @apartments = [] + end + + def view_apartments + puts "-----------Full Apartments List-----------" + @apartments.each do |apartment| + puts apartment + apartments.to_s + end + end + + def view_renters + puts "------------HighRise Luxury Renters List--------------" + @apartments.each do |apartment| + if apartment.is_rented? + puts "Name: #{apartment.renter} \t Unit: #{apartment.name}" + else + puts "Unit #{apartment.name} is empty" + + end + end + end + +end \ No newline at end of file diff --git a/Wk 3/week 3 lab/lib/person.rb b/Wk 3/week 3 lab/lib/person.rb new file mode 100644 index 0000000..1a01871 --- /dev/null +++ b/Wk 3/week 3 lab/lib/person.rb @@ -0,0 +1,14 @@ +class Person + attr_accessor :name, :credit_score, :gender + + def initialize (name, credit_score, gender) + @name = name + @credit_score = credit_score + @gender = gender + end + + def to_s + "#{name}" + end + +end diff --git a/Wk 3/week 3 lab/main.rb b/Wk 3/week 3 lab/main.rb new file mode 100644 index 0000000..48c7823 --- /dev/null +++ b/Wk 3/week 3 lab/main.rb @@ -0,0 +1,95 @@ +# Exercise Goal: This is an exercise in reading and writing code. +# => The purpose of this exercise is to practice creating classes. +# Task Instructions: +# => The main.rb file is where the application starts, and we've given you the code below. +# => Your job is to write the "Apartment", "Building" and "Person" classes. +# => Read the code below and use it to inform what variables and methods are necessary for each of the classes listed above. +# => We've also provided a png file of the terminal output from the completed version. +# => Hint: Think before you code. Annotate code and comment out sections as you test different sections + +require_relative 'lib/building' +require_relative 'lib/apartment' +require_relative 'lib/person' + +## First, define our methods + +def create_apartment + puts "-----------New Apartment-----------" + puts "What is the apartment number / name?" + name = gets.strip + + puts "How many square feet is apartment #{name}?" + apt_sqft = gets.to_i + + puts "How many bedrooms does apartment #{name} have?" + apt_bedrooms = gets.to_i + + puts "How many bathrooms does apartment #{name} have?" + apt_bathrooms = gets.to_i + + Apartment.new(name, apt_sqft, apt_bedrooms, apt_bathrooms) +end + +def create_renter + puts "-----------New Renter-----------" + puts "What is the renter's name?" + name = gets.strip + + puts "What is the #{name}'s credit score?" + credit_score = gets.to_i + + puts "Is #{name} male or female?" + gender = gets.strip + + Person.new(name, credit_score, gender) +end + +def create_building + puts "-----------New Building-----------" + puts "What is the building's name?" + building_name = gets.strip + + puts "What is the building's address?" + building_address = gets.strip + + Building.new(building_name, building_address) +end + +# Now call methods to run the program + +puts "******************Welcome to Ruby Building Manager****************** \n \n \n" + +building = create_building + +puts "How many units are there?" +apt_count = gets.to_i + + 0.upto(apt_count - 1) do |unit| + apartment = create_apartment + building.apartments[unit] = apartment + + puts "Apartment added successfully \n #{apartment}" + + puts "Is unit #{apartment.name} rented? (y)es (n)o" + unit_rented = gets.strip + + if unit_rented == "y" + apartment.renter = create_renter + puts "Renter added successfully" + + puts "How much is this unit rented for?" + rent = gets.to_i + apartment.rent = rent + end +end + +puts "What would you like to do next, (v)iew all apartments? (q)uit (r) show renters?" +response = gets.strip + +if response == 'v' + building.view_apartments +elsif response == 'r' + building.view_renters +else + puts "Thanks for using Ruby Building Manager" +end \ No newline at end of file diff --git a/Wk 3/week3.rb b/Wk 3/week3.rb new file mode 100644 index 0000000..e5de92d --- /dev/null +++ b/Wk 3/week3.rb @@ -0,0 +1,65 @@ +# jimmy ={} +# jimmy[:name] = "Jimmy J" +# jimmy[:major] = "Math" +# jimmy[:course] = "Math" +# jimmy[:grade] = "A" + +# ed ={} +# ed[:name] = "Eddy E" +# ed[:major] = "English" +# ed[:course] = "Math" +# ed[:grade] = "C" + +# ted ={} +# ted[:name] = "Teddy T" +# ted[:major] = "Math" +# ted[:course] = "English" +# ted[:grade] = "A" + + +class Student + attr_accessor :name, :major, :course, :grade + + def initialize(n, major, course, grade) + @name = n + @major = major + @course = course + @grade = grade + end + + def grade_status + if @grade == "F" + "failed" + elsif ["D", "E"].include?(@grade) && @major == @course + "failed" + else + "passed" + end + end + + def compare(other_student) + + end + + def to_s + puts "#{@name} has #{grade_status} #{@course}" + end +end + +# jimmy = Student.new +# jimmy.name = "Jimmy J" +# jimmy.major = "Math" +# jimmy.course = "Math" +# jimmy.grade = "A" + +# ed = Student.new +# ed.name = "Ed D" +# ed.major = "English" +# ed.course = "Math" +# ed.grade = "D" + +tom = Student.new("tom","classics","math","F") + +# puts "#{jimmy.name} has #{jimmy.grade_status} #{jimmy.course}" +# puts "#{ed.name} has #{ed.grade_status} #{ed.course}" +puts tom \ No newline at end of file diff --git a/wk4/User_Scaffold/.gitignore b/wk4/User_Scaffold/.gitignore new file mode 100644 index 0000000..6a502e9 --- /dev/null +++ b/wk4/User_Scaffold/.gitignore @@ -0,0 +1,16 @@ +# See https://help.github.com/articles/ignoring-files for more about ignoring files. +# +# If you find yourself ignoring temporary files generated by your text editor +# or operating system, you probably want to add a global ignore instead: +# git config --global core.excludesfile '~/.gitignore_global' + +# Ignore bundler config. +/.bundle + +# Ignore the default SQLite database. +/db/*.sqlite3 +/db/*.sqlite3-journal + +# Ignore all logfiles and tempfiles. +/log/*.log +/tmp diff --git a/wk4/User_Scaffold/Gemfile b/wk4/User_Scaffold/Gemfile new file mode 100644 index 0000000..21fc07e --- /dev/null +++ b/wk4/User_Scaffold/Gemfile @@ -0,0 +1,40 @@ +source 'https://rubygems.org' + + +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' +gem 'rails', '4.1.1' +# Use sqlite3 as the database for Active Record +gem 'sqlite3' +# Use SCSS for stylesheets +gem 'sass-rails', '~> 4.0.3' +# Use Uglifier as compressor for JavaScript assets +gem 'uglifier', '>= 1.3.0' +# Use CoffeeScript for .js.coffee assets and views +gem 'coffee-rails', '~> 4.0.0' +# See https://github.com/sstephenson/execjs#readme for more supported runtimes +# gem 'therubyracer', platforms: :ruby + +# Use jquery as the JavaScript library +gem 'jquery-rails' +# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks +gem 'turbolinks' +# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder +gem 'jbuilder', '~> 2.0' +# bundle exec rake doc:rails generates the API under doc/api. +gem 'sdoc', '~> 0.4.0', group: :doc + +# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring +gem 'spring', group: :development + +# Use ActiveModel has_secure_password +# gem 'bcrypt', '~> 3.1.7' + +# Use unicorn as the app server +# gem 'unicorn' + +# Use Capistrano for deployment +# gem 'capistrano-rails', group: :development + +# Use debugger +# gem 'debugger', group: [:development, :test] + diff --git a/wk4/User_Scaffold/Gemfile.lock b/wk4/User_Scaffold/Gemfile.lock new file mode 100644 index 0000000..2ec60ab --- /dev/null +++ b/wk4/User_Scaffold/Gemfile.lock @@ -0,0 +1,125 @@ +GEM + remote: https://rubygems.org/ + specs: + actionmailer (4.1.1) + actionpack (= 4.1.1) + actionview (= 4.1.1) + mail (~> 2.5.4) + actionpack (4.1.1) + actionview (= 4.1.1) + activesupport (= 4.1.1) + rack (~> 1.5.2) + rack-test (~> 0.6.2) + actionview (4.1.1) + activesupport (= 4.1.1) + builder (~> 3.1) + erubis (~> 2.7.0) + activemodel (4.1.1) + activesupport (= 4.1.1) + builder (~> 3.1) + activerecord (4.1.1) + activemodel (= 4.1.1) + activesupport (= 4.1.1) + arel (~> 5.0.0) + activesupport (4.1.1) + i18n (~> 0.6, >= 0.6.9) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) + thread_safe (~> 0.1) + tzinfo (~> 1.1) + arel (5.0.1.20140414130214) + builder (3.2.2) + coffee-rails (4.0.1) + coffee-script (>= 2.2.0) + railties (>= 4.0.0, < 5.0) + coffee-script (2.2.0) + coffee-script-source + execjs + coffee-script-source (1.7.0) + erubis (2.7.0) + execjs (2.2.0) + hike (1.2.3) + i18n (0.6.9) + jbuilder (2.1.0) + activesupport (>= 3.0.0, < 5) + multi_json (~> 1.2) + jquery-rails (3.1.0) + railties (>= 3.0, < 5.0) + thor (>= 0.14, < 2.0) + json (1.8.1) + mail (2.5.4) + mime-types (~> 1.16) + treetop (~> 1.4.8) + mime-types (1.25.1) + minitest (5.3.4) + multi_json (1.10.1) + polyglot (0.3.5) + rack (1.5.2) + rack-test (0.6.2) + rack (>= 1.0) + rails (4.1.1) + actionmailer (= 4.1.1) + actionpack (= 4.1.1) + actionview (= 4.1.1) + activemodel (= 4.1.1) + activerecord (= 4.1.1) + activesupport (= 4.1.1) + bundler (>= 1.3.0, < 2.0) + railties (= 4.1.1) + sprockets-rails (~> 2.0) + railties (4.1.1) + actionpack (= 4.1.1) + activesupport (= 4.1.1) + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (10.3.2) + rdoc (4.1.1) + json (~> 1.4) + sass (3.2.19) + sass-rails (4.0.3) + railties (>= 4.0.0, < 5.0) + sass (~> 3.2.0) + sprockets (~> 2.8, <= 2.11.0) + sprockets-rails (~> 2.0) + sdoc (0.4.0) + json (~> 1.8) + rdoc (~> 4.0, < 5.0) + spring (1.1.3) + sprockets (2.11.0) + hike (~> 1.2) + multi_json (~> 1.0) + rack (~> 1.0) + tilt (~> 1.1, != 1.3.0) + sprockets-rails (2.1.3) + actionpack (>= 3.0) + activesupport (>= 3.0) + sprockets (~> 2.8) + sqlite3 (1.3.9) + thor (0.19.1) + thread_safe (0.3.4) + tilt (1.4.1) + treetop (1.4.15) + polyglot + polyglot (>= 0.3.1) + turbolinks (2.2.2) + coffee-rails + tzinfo (1.2.1) + thread_safe (~> 0.1) + uglifier (2.5.0) + execjs (>= 0.3.0) + json (>= 1.8.0) + +PLATFORMS + ruby + +DEPENDENCIES + coffee-rails (~> 4.0.0) + jbuilder (~> 2.0) + jquery-rails + rails (= 4.1.1) + sass-rails (~> 4.0.3) + sdoc (~> 0.4.0) + spring + sqlite3 + turbolinks + uglifier (>= 1.3.0) diff --git a/wk4/User_Scaffold/README.rdoc b/wk4/User_Scaffold/README.rdoc new file mode 100644 index 0000000..dd4e97e --- /dev/null +++ b/wk4/User_Scaffold/README.rdoc @@ -0,0 +1,28 @@ +== README + +This README would normally document whatever steps are necessary to get the +application up and running. + +Things you may want to cover: + +* Ruby version + +* System dependencies + +* Configuration + +* Database creation + +* Database initialization + +* How to run the test suite + +* Services (job queues, cache servers, search engines, etc.) + +* Deployment instructions + +* ... + + +Please feel free to use a different markup language if you do not plan to run +rake doc:app. diff --git a/wk4/User_Scaffold/Rakefile b/wk4/User_Scaffold/Rakefile new file mode 100644 index 0000000..ba6b733 --- /dev/null +++ b/wk4/User_Scaffold/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require File.expand_path('../config/application', __FILE__) + +Rails.application.load_tasks diff --git a/wk4/User_Scaffold/app/assets/images/.keep b/wk4/User_Scaffold/app/assets/images/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/User_Scaffold/app/assets/javascripts/application.js b/wk4/User_Scaffold/app/assets/javascripts/application.js new file mode 100644 index 0000000..d6925fa --- /dev/null +++ b/wk4/User_Scaffold/app/assets/javascripts/application.js @@ -0,0 +1,16 @@ +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, +// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// compiled file. +// +// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details +// about supported directives. +// +//= require jquery +//= require jquery_ujs +//= require turbolinks +//= require_tree . diff --git a/wk4/User_Scaffold/app/assets/javascripts/users.js.coffee b/wk4/User_Scaffold/app/assets/javascripts/users.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/wk4/User_Scaffold/app/assets/javascripts/users.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/wk4/User_Scaffold/app/assets/stylesheets/application.css b/wk4/User_Scaffold/app/assets/stylesheets/application.css new file mode 100644 index 0000000..a443db3 --- /dev/null +++ b/wk4/User_Scaffold/app/assets/stylesheets/application.css @@ -0,0 +1,15 @@ +/* + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, + * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the bottom of the + * compiled file so the styles you add here take precedence over styles defined in any styles + * defined in the other CSS/SCSS files in this directory. It is generally better to create a new + * file per style scope. + * + *= require_tree . + *= require_self + */ diff --git a/wk4/User_Scaffold/app/assets/stylesheets/scaffolds.css.scss b/wk4/User_Scaffold/app/assets/stylesheets/scaffolds.css.scss new file mode 100644 index 0000000..6ec6a8f --- /dev/null +++ b/wk4/User_Scaffold/app/assets/stylesheets/scaffolds.css.scss @@ -0,0 +1,69 @@ +body { + background-color: #fff; + color: #333; + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +p, ol, ul, td { + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +pre { + background-color: #eee; + padding: 10px; + font-size: 11px; +} + +a { + color: #000; + &:visited { + color: #666; + } + &:hover { + color: #fff; + background-color: #000; + } +} + +div { + &.field, &.actions { + margin-bottom: 10px; + } +} + +#notice { + color: green; +} + +.field_with_errors { + padding: 2px; + background-color: red; + display: table; +} + +#error_explanation { + width: 450px; + border: 2px solid red; + padding: 7px; + padding-bottom: 0; + margin-bottom: 20px; + background-color: #f0f0f0; + h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px; + margin-bottom: 0px; + background-color: #c00; + color: #fff; + } + ul li { + font-size: 12px; + list-style: square; + } +} diff --git a/wk4/User_Scaffold/app/assets/stylesheets/users.css.scss b/wk4/User_Scaffold/app/assets/stylesheets/users.css.scss new file mode 100644 index 0000000..31a2eac --- /dev/null +++ b/wk4/User_Scaffold/app/assets/stylesheets/users.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Users controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/wk4/User_Scaffold/app/controllers/application_controller.rb b/wk4/User_Scaffold/app/controllers/application_controller.rb new file mode 100644 index 0000000..d83690e --- /dev/null +++ b/wk4/User_Scaffold/app/controllers/application_controller.rb @@ -0,0 +1,5 @@ +class ApplicationController < ActionController::Base + # Prevent CSRF attacks by raising an exception. + # For APIs, you may want to use :null_session instead. + protect_from_forgery with: :exception +end diff --git a/wk4/User_Scaffold/app/controllers/concerns/.keep b/wk4/User_Scaffold/app/controllers/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/User_Scaffold/app/controllers/users_controller.rb b/wk4/User_Scaffold/app/controllers/users_controller.rb new file mode 100644 index 0000000..d74534e --- /dev/null +++ b/wk4/User_Scaffold/app/controllers/users_controller.rb @@ -0,0 +1,74 @@ +class UsersController < ApplicationController + before_action :set_user, only: [:show, :edit, :update, :destroy] + + # GET /users + # GET /users.json + def index + @users = User.all + end + + # GET /users/1 + # GET /users/1.json + def show + end + + # GET /users/new + def new + @user = User.new + end + + # GET /users/1/edit + def edit + end + + # POST /users + # POST /users.json + def create + @user = User.new(user_params) + + respond_to do |format| + if @user.save + format.html { redirect_to @user, notice: 'User was successfully created.' } + format.json { render :show, status: :created, location: @user } + else + format.html { render :new } + format.json { render json: @user.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /users/1 + # PATCH/PUT /users/1.json + def update + respond_to do |format| + if @user.update(user_params) + format.html { redirect_to @user, notice: 'User was successfully updated.' } + format.json { render :show, status: :ok, location: @user } + else + format.html { render :edit } + format.json { render json: @user.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /users/1 + # DELETE /users/1.json + def destroy + @user.destroy + respond_to do |format| + format.html { redirect_to users_url, notice: 'User was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_user + @user = User.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def user_params + params.require(:user).permit(:first_name, :last_name, :age, :email) + end +end diff --git a/wk4/User_Scaffold/app/helpers/application_helper.rb b/wk4/User_Scaffold/app/helpers/application_helper.rb new file mode 100644 index 0000000..de6be79 --- /dev/null +++ b/wk4/User_Scaffold/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/wk4/User_Scaffold/app/helpers/users_helper.rb b/wk4/User_Scaffold/app/helpers/users_helper.rb new file mode 100644 index 0000000..2310a24 --- /dev/null +++ b/wk4/User_Scaffold/app/helpers/users_helper.rb @@ -0,0 +1,2 @@ +module UsersHelper +end diff --git a/wk4/User_Scaffold/app/mailers/.keep b/wk4/User_Scaffold/app/mailers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/User_Scaffold/app/models/.keep b/wk4/User_Scaffold/app/models/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/User_Scaffold/app/models/concerns/.keep b/wk4/User_Scaffold/app/models/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/User_Scaffold/app/models/user.rb b/wk4/User_Scaffold/app/models/user.rb new file mode 100644 index 0000000..4a57cf0 --- /dev/null +++ b/wk4/User_Scaffold/app/models/user.rb @@ -0,0 +1,2 @@ +class User < ActiveRecord::Base +end diff --git a/wk4/User_Scaffold/app/views/layouts/application.html.erb b/wk4/User_Scaffold/app/views/layouts/application.html.erb new file mode 100644 index 0000000..99bf852 --- /dev/null +++ b/wk4/User_Scaffold/app/views/layouts/application.html.erb @@ -0,0 +1,14 @@ + + + + UserScaffold + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> + <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> + <%= csrf_meta_tags %> + + + +<%= yield %> + + + diff --git a/wk4/User_Scaffold/app/views/users/_form.html.erb b/wk4/User_Scaffold/app/views/users/_form.html.erb new file mode 100644 index 0000000..e7d0e34 --- /dev/null +++ b/wk4/User_Scaffold/app/views/users/_form.html.erb @@ -0,0 +1,33 @@ +<%= form_for(@user) do |f| %> + <% if @user.errors.any? %> +
+

<%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:

+ +
    + <% @user.errors.full_messages.each do |message| %> +
  • <%= message %>
  • + <% end %> +
+
+ <% end %> + +
+ <%= f.label :first_name %>
+ <%= f.text_field :first_name %> +
+
+ <%= f.label :last_name %>
+ <%= f.text_field :last_name %> +
+
+ <%= f.label :age %>
+ <%= f.number_field :age %> +
+
+ <%= f.label :email %>
+ <%= f.text_field :email %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/wk4/User_Scaffold/app/views/users/edit.html.erb b/wk4/User_Scaffold/app/views/users/edit.html.erb new file mode 100644 index 0000000..99bd4cc --- /dev/null +++ b/wk4/User_Scaffold/app/views/users/edit.html.erb @@ -0,0 +1,6 @@ +

Editing user

+ +<%= render 'form' %> + +<%= link_to 'Show', @user %> | +<%= link_to 'Back', users_path %> diff --git a/wk4/User_Scaffold/app/views/users/index.html.erb b/wk4/User_Scaffold/app/views/users/index.html.erb new file mode 100644 index 0000000..02dd61b --- /dev/null +++ b/wk4/User_Scaffold/app/views/users/index.html.erb @@ -0,0 +1,31 @@ +

Listing users

+ + + + + + + + + + + + + + <% @users.each do |user| %> + + + + + + + + + + <% end %> + +
First nameLast nameAgeEmail
<%= user.first_name %><%= user.last_name %><%= user.age %><%= user.email %><%= link_to 'Show', user %><%= link_to 'Edit', edit_user_path(user) %><%= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New User', new_user_path %> diff --git a/wk4/User_Scaffold/app/views/users/index.json.jbuilder b/wk4/User_Scaffold/app/views/users/index.json.jbuilder new file mode 100644 index 0000000..db78fa6 --- /dev/null +++ b/wk4/User_Scaffold/app/views/users/index.json.jbuilder @@ -0,0 +1,4 @@ +json.array!(@users) do |user| + json.extract! user, :id, :first_name, :last_name, :age, :email + json.url user_url(user, format: :json) +end diff --git a/wk4/User_Scaffold/app/views/users/new.html.erb b/wk4/User_Scaffold/app/views/users/new.html.erb new file mode 100644 index 0000000..efc0404 --- /dev/null +++ b/wk4/User_Scaffold/app/views/users/new.html.erb @@ -0,0 +1,5 @@ +

New user

+ +<%= render 'form' %> + +<%= link_to 'Back', users_path %> diff --git a/wk4/User_Scaffold/app/views/users/show.html.erb b/wk4/User_Scaffold/app/views/users/show.html.erb new file mode 100644 index 0000000..4ae37eb --- /dev/null +++ b/wk4/User_Scaffold/app/views/users/show.html.erb @@ -0,0 +1,24 @@ +

<%= notice %>

+ +

+ First name: + <%= @user.first_name %> +

+ +

+ Last name: + <%= @user.last_name %> +

+ +

+ Age: + <%= @user.age %> +

+ +

+ Email: + <%= @user.email %> +

+ +<%= link_to 'Edit', edit_user_path(@user) %> | +<%= link_to 'Back', users_path %> diff --git a/wk4/User_Scaffold/app/views/users/show.json.jbuilder b/wk4/User_Scaffold/app/views/users/show.json.jbuilder new file mode 100644 index 0000000..e786850 --- /dev/null +++ b/wk4/User_Scaffold/app/views/users/show.json.jbuilder @@ -0,0 +1 @@ +json.extract! @user, :id, :first_name, :last_name, :age, :email, :created_at, :updated_at diff --git a/wk4/User_Scaffold/bin/bundle b/wk4/User_Scaffold/bin/bundle new file mode 100755 index 0000000..66e9889 --- /dev/null +++ b/wk4/User_Scaffold/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +load Gem.bin_path('bundler', 'bundle') diff --git a/wk4/User_Scaffold/bin/rails b/wk4/User_Scaffold/bin/rails new file mode 100755 index 0000000..7feb6a3 --- /dev/null +++ b/wk4/User_Scaffold/bin/rails @@ -0,0 +1,8 @@ +#!/usr/bin/env ruby +begin + load File.expand_path("../spring", __FILE__) +rescue LoadError +end +APP_PATH = File.expand_path('../../config/application', __FILE__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/wk4/User_Scaffold/bin/rake b/wk4/User_Scaffold/bin/rake new file mode 100755 index 0000000..8017a02 --- /dev/null +++ b/wk4/User_Scaffold/bin/rake @@ -0,0 +1,8 @@ +#!/usr/bin/env ruby +begin + load File.expand_path("../spring", __FILE__) +rescue LoadError +end +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/wk4/User_Scaffold/bin/spring b/wk4/User_Scaffold/bin/spring new file mode 100755 index 0000000..253ec37 --- /dev/null +++ b/wk4/User_Scaffold/bin/spring @@ -0,0 +1,18 @@ +#!/usr/bin/env ruby + +# This file loads spring without using Bundler, in order to be fast +# It gets overwritten when you run the `spring binstub` command + +unless defined?(Spring) + require "rubygems" + require "bundler" + + if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ spring \((.*?)\)$.*?^$/m) + ENV["GEM_PATH"] = ([Bundler.bundle_path.to_s] + Gem.path).join(File::PATH_SEPARATOR) + ENV["GEM_HOME"] = "" + Gem.paths = ENV + + gem "spring", match[1] + require "spring/binstub" + end +end diff --git a/wk4/User_Scaffold/config.ru b/wk4/User_Scaffold/config.ru new file mode 100644 index 0000000..5bc2a61 --- /dev/null +++ b/wk4/User_Scaffold/config.ru @@ -0,0 +1,4 @@ +# This file is used by Rack-based servers to start the application. + +require ::File.expand_path('../config/environment', __FILE__) +run Rails.application diff --git a/wk4/User_Scaffold/config/application.rb b/wk4/User_Scaffold/config/application.rb new file mode 100644 index 0000000..bc23702 --- /dev/null +++ b/wk4/User_Scaffold/config/application.rb @@ -0,0 +1,23 @@ +require File.expand_path('../boot', __FILE__) + +require 'rails/all' + +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(*Rails.groups) + +module UserScaffold + class Application < Rails::Application + # Settings in config/environments/* take precedence over those specified here. + # Application configuration should go into files in config/initializers + # -- all .rb files in that directory are automatically loaded. + + # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. + # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. + # config.time_zone = 'Central Time (US & Canada)' + + # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. + # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] + # config.i18n.default_locale = :de + end +end diff --git a/wk4/User_Scaffold/config/boot.rb b/wk4/User_Scaffold/config/boot.rb new file mode 100644 index 0000000..5e5f0c1 --- /dev/null +++ b/wk4/User_Scaffold/config/boot.rb @@ -0,0 +1,4 @@ +# Set up gems listed in the Gemfile. +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) + +require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) diff --git a/wk4/User_Scaffold/config/database.yml b/wk4/User_Scaffold/config/database.yml new file mode 100644 index 0000000..1c1a37c --- /dev/null +++ b/wk4/User_Scaffold/config/database.yml @@ -0,0 +1,25 @@ +# SQLite version 3.x +# gem install sqlite3 +# +# Ensure the SQLite 3 gem is defined in your Gemfile +# gem 'sqlite3' +# +default: &default + adapter: sqlite3 + pool: 5 + timeout: 5000 + +development: + <<: *default + database: db/development.sqlite3 + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: db/test.sqlite3 + +production: + <<: *default + database: db/production.sqlite3 diff --git a/wk4/User_Scaffold/config/environment.rb b/wk4/User_Scaffold/config/environment.rb new file mode 100644 index 0000000..ee8d90d --- /dev/null +++ b/wk4/User_Scaffold/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require File.expand_path('../application', __FILE__) + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/wk4/User_Scaffold/config/environments/development.rb b/wk4/User_Scaffold/config/environments/development.rb new file mode 100644 index 0000000..ddf0e90 --- /dev/null +++ b/wk4/User_Scaffold/config/environments/development.rb @@ -0,0 +1,37 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + # Debug mode disables concatenation and preprocessing of assets. + # This option may cause significant delays in view rendering with a large + # number of complex assets. + config.assets.debug = true + + # Adds additional error checking when serving assets at runtime. + # Checks for improperly declared sprockets dependencies. + # Raises helpful error messages. + config.assets.raise_runtime_errors = true + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true +end diff --git a/wk4/User_Scaffold/config/environments/production.rb b/wk4/User_Scaffold/config/environments/production.rb new file mode 100644 index 0000000..47d3553 --- /dev/null +++ b/wk4/User_Scaffold/config/environments/production.rb @@ -0,0 +1,83 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Enable Rack::Cache to put a simple HTTP cache in front of your application + # Add `rack-cache` to your Gemfile before enabling this. + # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid. + # config.action_dispatch.rack_cache = true + + # Disable Rails's static asset server (Apache or nginx will already do this). + config.serve_static_assets = false + + # Compress JavaScripts and CSS. + config.assets.js_compressor = :uglifier + # config.assets.css_compressor = :sass + + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = false + + # Generate digests for assets URLs. + config.assets.digest = true + + # Version of your assets, change this if you want to expire all your assets. + config.assets.version = '1.0' + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Set to :debug to see everything in the log. + config.log_level = :info + + # Prepend all log lines with the following tags. + # config.log_tags = [ :subdomain, :uuid ] + + # Use a different logger for distributed setups. + # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = "http://assets.example.com" + + # Precompile additional assets. + # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. + # config.assets.precompile += %w( search.js ) + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Disable automatic flushing of the log to improve performance. + # config.autoflush_log = false + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false +end diff --git a/wk4/User_Scaffold/config/environments/test.rb b/wk4/User_Scaffold/config/environments/test.rb new file mode 100644 index 0000000..053f5b6 --- /dev/null +++ b/wk4/User_Scaffold/config/environments/test.rb @@ -0,0 +1,39 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # The test environment is used exclusively to run your application's + # test suite. You never need to work with it otherwise. Remember that + # your test database is "scratch space" for the test suite and is wiped + # and recreated between test runs. Don't rely on the data there! + config.cache_classes = true + + # Do not eager load code on boot. This avoids loading your whole application + # just for the purpose of running a single test. If you are using a tool that + # preloads Rails for running tests, you may have to set it to true. + config.eager_load = false + + # Configure static asset server for tests with Cache-Control for performance. + config.serve_static_assets = true + config.static_cache_control = 'public, max-age=3600' + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Raise exceptions instead of rendering exception templates. + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true +end diff --git a/wk4/User_Scaffold/config/initializers/backtrace_silencers.rb b/wk4/User_Scaffold/config/initializers/backtrace_silencers.rb new file mode 100644 index 0000000..59385cd --- /dev/null +++ b/wk4/User_Scaffold/config/initializers/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# Rails.backtrace_cleaner.remove_silencers! diff --git a/wk4/User_Scaffold/config/initializers/cookies_serializer.rb b/wk4/User_Scaffold/config/initializers/cookies_serializer.rb new file mode 100644 index 0000000..7a06a89 --- /dev/null +++ b/wk4/User_Scaffold/config/initializers/cookies_serializer.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +Rails.application.config.action_dispatch.cookies_serializer = :json \ No newline at end of file diff --git a/wk4/User_Scaffold/config/initializers/filter_parameter_logging.rb b/wk4/User_Scaffold/config/initializers/filter_parameter_logging.rb new file mode 100644 index 0000000..4a994e1 --- /dev/null +++ b/wk4/User_Scaffold/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Configure sensitive parameters which will be filtered from the log file. +Rails.application.config.filter_parameters += [:password] diff --git a/wk4/User_Scaffold/config/initializers/inflections.rb b/wk4/User_Scaffold/config/initializers/inflections.rb new file mode 100644 index 0000000..ac033bf --- /dev/null +++ b/wk4/User_Scaffold/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/wk4/User_Scaffold/config/initializers/mime_types.rb b/wk4/User_Scaffold/config/initializers/mime_types.rb new file mode 100644 index 0000000..dc18996 --- /dev/null +++ b/wk4/User_Scaffold/config/initializers/mime_types.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf diff --git a/wk4/User_Scaffold/config/initializers/session_store.rb b/wk4/User_Scaffold/config/initializers/session_store.rb new file mode 100644 index 0000000..e7d82e8 --- /dev/null +++ b/wk4/User_Scaffold/config/initializers/session_store.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +Rails.application.config.session_store :cookie_store, key: '_User_Scaffold_session' diff --git a/wk4/User_Scaffold/config/initializers/wrap_parameters.rb b/wk4/User_Scaffold/config/initializers/wrap_parameters.rb new file mode 100644 index 0000000..33725e9 --- /dev/null +++ b/wk4/User_Scaffold/config/initializers/wrap_parameters.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. + +# This file contains settings for ActionController::ParamsWrapper which +# is enabled by default. + +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. +ActiveSupport.on_load(:action_controller) do + wrap_parameters format: [:json] if respond_to?(:wrap_parameters) +end + +# To enable root element in JSON for ActiveRecord objects. +# ActiveSupport.on_load(:active_record) do +# self.include_root_in_json = true +# end diff --git a/wk4/User_Scaffold/config/locales/en.yml b/wk4/User_Scaffold/config/locales/en.yml new file mode 100644 index 0000000..0653957 --- /dev/null +++ b/wk4/User_Scaffold/config/locales/en.yml @@ -0,0 +1,23 @@ +# Files in the config/locales directory are used for internationalization +# and are automatically loaded by Rails. If you want to use locales other +# than English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t 'hello' +# +# In views, this is aliased to just `t`: +# +# <%= t('hello') %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# To learn more, please read the Rails Internationalization guide +# available at http://guides.rubyonrails.org/i18n.html. + +en: + hello: "Hello world" diff --git a/wk4/User_Scaffold/config/routes.rb b/wk4/User_Scaffold/config/routes.rb new file mode 100644 index 0000000..bdbc195 --- /dev/null +++ b/wk4/User_Scaffold/config/routes.rb @@ -0,0 +1,58 @@ +Rails.application.routes.draw do + resources :users + + # The priority is based upon order of creation: first created -> highest priority. + # See how all your routes lay out with "rake routes". + + # You can have the root of your site routed with "root" + # root 'welcome#index' + + # Example of regular route: + # get 'products/:id' => 'catalog#view' + + # Example of named route that can be invoked with purchase_url(id: product.id) + # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase + + # Example resource route (maps HTTP verbs to controller actions automatically): + # resources :products + + # Example resource route with options: + # resources :products do + # member do + # get 'short' + # post 'toggle' + # end + # + # collection do + # get 'sold' + # end + # end + + # Example resource route with sub-resources: + # resources :products do + # resources :comments, :sales + # resource :seller + # end + + # Example resource route with more complex sub-resources: + # resources :products do + # resources :comments + # resources :sales do + # get 'recent', on: :collection + # end + # end + + # Example resource route with concerns: + # concern :toggleable do + # post 'toggle' + # end + # resources :posts, concerns: :toggleable + # resources :photos, concerns: :toggleable + + # Example resource route within a namespace: + # namespace :admin do + # # Directs /admin/products/* to Admin::ProductsController + # # (app/controllers/admin/products_controller.rb) + # resources :products + # end +end diff --git a/wk4/User_Scaffold/config/secrets.yml b/wk4/User_Scaffold/config/secrets.yml new file mode 100644 index 0000000..6ae01c3 --- /dev/null +++ b/wk4/User_Scaffold/config/secrets.yml @@ -0,0 +1,22 @@ +# Be sure to restart your server when you modify this file. + +# Your secret key is used for verifying the integrity of signed cookies. +# If you change this key, all old signed cookies will become invalid! + +# Make sure the secret is at least 30 characters and all random, +# no regular words or you'll be exposed to dictionary attacks. +# You can use `rake secret` to generate a secure secret key. + +# Make sure the secrets in this file are kept private +# if you're sharing your code publicly. + +development: + secret_key_base: 9c2cdae1f04516704864364a1c6ae0256e43dcfe4e6f704d96fac907e69f90539bfe70a17f5421079ced8244e8b0e7723994e5b958a7ee8e737c9977b6cc1fa9 + +test: + secret_key_base: 7e8227586413ea2a2fa5aff7756f772ca256cbc130e6397f99536eb6a8c49cc4a63902fe3f056db64fc024416e800e1811f98d17333da8554fd205ce962116c9 + +# Do not keep production secrets in the repository, +# instead read values from the environment. +production: + secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> diff --git a/wk4/User_Scaffold/db/migrate/20140611025626_create_users.rb b/wk4/User_Scaffold/db/migrate/20140611025626_create_users.rb new file mode 100644 index 0000000..b73c5c4 --- /dev/null +++ b/wk4/User_Scaffold/db/migrate/20140611025626_create_users.rb @@ -0,0 +1,12 @@ +class CreateUsers < ActiveRecord::Migration + def change + create_table :users do |t| + t.string :first_name + t.string :last_name + t.integer :age + t.string :email + + t.timestamps + end + end +end diff --git a/wk4/User_Scaffold/db/schema.rb b/wk4/User_Scaffold/db/schema.rb new file mode 100644 index 0000000..e658d2c --- /dev/null +++ b/wk4/User_Scaffold/db/schema.rb @@ -0,0 +1,25 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20140611025626) do + + create_table "users", force: true do |t| + t.string "first_name" + t.string "last_name" + t.integer "age" + t.string "email" + t.datetime "created_at" + t.datetime "updated_at" + end + +end diff --git a/wk4/User_Scaffold/db/seeds.rb b/wk4/User_Scaffold/db/seeds.rb new file mode 100644 index 0000000..4edb1e8 --- /dev/null +++ b/wk4/User_Scaffold/db/seeds.rb @@ -0,0 +1,7 @@ +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). +# +# Examples: +# +# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) +# Mayor.create(name: 'Emanuel', city: cities.first) diff --git a/wk4/User_Scaffold/lib/assets/.keep b/wk4/User_Scaffold/lib/assets/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/User_Scaffold/lib/tasks/.keep b/wk4/User_Scaffold/lib/tasks/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/User_Scaffold/log/.keep b/wk4/User_Scaffold/log/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/User_Scaffold/public/404.html b/wk4/User_Scaffold/public/404.html new file mode 100644 index 0000000..b612547 --- /dev/null +++ b/wk4/User_Scaffold/public/404.html @@ -0,0 +1,67 @@ + + + + The page you were looking for doesn't exist (404) + + + + + + +
+
+

The page you were looking for doesn't exist.

+

You may have mistyped the address or the page may have moved.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/wk4/User_Scaffold/public/422.html b/wk4/User_Scaffold/public/422.html new file mode 100644 index 0000000..a21f82b --- /dev/null +++ b/wk4/User_Scaffold/public/422.html @@ -0,0 +1,67 @@ + + + + The change you wanted was rejected (422) + + + + + + +
+
+

The change you wanted was rejected.

+

Maybe you tried to change something you didn't have access to.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/wk4/User_Scaffold/public/500.html b/wk4/User_Scaffold/public/500.html new file mode 100644 index 0000000..061abc5 --- /dev/null +++ b/wk4/User_Scaffold/public/500.html @@ -0,0 +1,66 @@ + + + + We're sorry, but something went wrong (500) + + + + + + +
+
+

We're sorry, but something went wrong.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/wk4/User_Scaffold/public/favicon.ico b/wk4/User_Scaffold/public/favicon.ico new file mode 100644 index 0000000..e69de29 diff --git a/wk4/User_Scaffold/public/robots.txt b/wk4/User_Scaffold/public/robots.txt new file mode 100644 index 0000000..3c9c7c0 --- /dev/null +++ b/wk4/User_Scaffold/public/robots.txt @@ -0,0 +1,5 @@ +# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file +# +# To ban all spiders from the entire site uncomment the next two lines: +# User-agent: * +# Disallow: / diff --git a/wk4/User_Scaffold/test/controllers/.keep b/wk4/User_Scaffold/test/controllers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/User_Scaffold/test/controllers/users_controller_test.rb b/wk4/User_Scaffold/test/controllers/users_controller_test.rb new file mode 100644 index 0000000..648d709 --- /dev/null +++ b/wk4/User_Scaffold/test/controllers/users_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class UsersControllerTest < ActionController::TestCase + setup do + @user = users(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:users) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create user" do + assert_difference('User.count') do + post :create, user: { age: @user.age, email: @user.email, first_name: @user.first_name, last_name: @user.last_name } + end + + assert_redirected_to user_path(assigns(:user)) + end + + test "should show user" do + get :show, id: @user + assert_response :success + end + + test "should get edit" do + get :edit, id: @user + assert_response :success + end + + test "should update user" do + patch :update, id: @user, user: { age: @user.age, email: @user.email, first_name: @user.first_name, last_name: @user.last_name } + assert_redirected_to user_path(assigns(:user)) + end + + test "should destroy user" do + assert_difference('User.count', -1) do + delete :destroy, id: @user + end + + assert_redirected_to users_path + end +end diff --git a/wk4/User_Scaffold/test/fixtures/.keep b/wk4/User_Scaffold/test/fixtures/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/User_Scaffold/test/fixtures/users.yml b/wk4/User_Scaffold/test/fixtures/users.yml new file mode 100644 index 0000000..00e4165 --- /dev/null +++ b/wk4/User_Scaffold/test/fixtures/users.yml @@ -0,0 +1,13 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + first_name: MyString + last_name: MyString + age: 1 + email: MyString + +two: + first_name: MyString + last_name: MyString + age: 1 + email: MyString diff --git a/wk4/User_Scaffold/test/helpers/.keep b/wk4/User_Scaffold/test/helpers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/User_Scaffold/test/helpers/users_helper_test.rb b/wk4/User_Scaffold/test/helpers/users_helper_test.rb new file mode 100644 index 0000000..96af37a --- /dev/null +++ b/wk4/User_Scaffold/test/helpers/users_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class UsersHelperTest < ActionView::TestCase +end diff --git a/wk4/User_Scaffold/test/integration/.keep b/wk4/User_Scaffold/test/integration/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/User_Scaffold/test/mailers/.keep b/wk4/User_Scaffold/test/mailers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/User_Scaffold/test/models/.keep b/wk4/User_Scaffold/test/models/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/User_Scaffold/test/models/user_test.rb b/wk4/User_Scaffold/test/models/user_test.rb new file mode 100644 index 0000000..82f61e0 --- /dev/null +++ b/wk4/User_Scaffold/test/models/user_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class UserTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/wk4/User_Scaffold/test/test_helper.rb b/wk4/User_Scaffold/test/test_helper.rb new file mode 100644 index 0000000..bf95f81 --- /dev/null +++ b/wk4/User_Scaffold/test/test_helper.rb @@ -0,0 +1,13 @@ +ENV['RAILS_ENV'] ||= 'test' +require File.expand_path('../../config/environment', __FILE__) +require 'rails/test_help' + +class ActiveSupport::TestCase + # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. + # + # Note: You'll currently still have to declare fixtures explicitly in integration tests + # -- they do not yet inherit this setting + fixtures :all + + # Add more helper methods to be used by all tests here... +end diff --git a/wk4/User_Scaffold/vendor/assets/javascripts/.keep b/wk4/User_Scaffold/vendor/assets/javascripts/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/User_Scaffold/vendor/assets/stylesheets/.keep b/wk4/User_Scaffold/vendor/assets/stylesheets/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/my_new_app/.gitignore b/wk4/my_new_app/.gitignore new file mode 100644 index 0000000..6a502e9 --- /dev/null +++ b/wk4/my_new_app/.gitignore @@ -0,0 +1,16 @@ +# See https://help.github.com/articles/ignoring-files for more about ignoring files. +# +# If you find yourself ignoring temporary files generated by your text editor +# or operating system, you probably want to add a global ignore instead: +# git config --global core.excludesfile '~/.gitignore_global' + +# Ignore bundler config. +/.bundle + +# Ignore the default SQLite database. +/db/*.sqlite3 +/db/*.sqlite3-journal + +# Ignore all logfiles and tempfiles. +/log/*.log +/tmp diff --git a/wk4/my_new_app/Gemfile b/wk4/my_new_app/Gemfile new file mode 100644 index 0000000..21fc07e --- /dev/null +++ b/wk4/my_new_app/Gemfile @@ -0,0 +1,40 @@ +source 'https://rubygems.org' + + +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' +gem 'rails', '4.1.1' +# Use sqlite3 as the database for Active Record +gem 'sqlite3' +# Use SCSS for stylesheets +gem 'sass-rails', '~> 4.0.3' +# Use Uglifier as compressor for JavaScript assets +gem 'uglifier', '>= 1.3.0' +# Use CoffeeScript for .js.coffee assets and views +gem 'coffee-rails', '~> 4.0.0' +# See https://github.com/sstephenson/execjs#readme for more supported runtimes +# gem 'therubyracer', platforms: :ruby + +# Use jquery as the JavaScript library +gem 'jquery-rails' +# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks +gem 'turbolinks' +# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder +gem 'jbuilder', '~> 2.0' +# bundle exec rake doc:rails generates the API under doc/api. +gem 'sdoc', '~> 0.4.0', group: :doc + +# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring +gem 'spring', group: :development + +# Use ActiveModel has_secure_password +# gem 'bcrypt', '~> 3.1.7' + +# Use unicorn as the app server +# gem 'unicorn' + +# Use Capistrano for deployment +# gem 'capistrano-rails', group: :development + +# Use debugger +# gem 'debugger', group: [:development, :test] + diff --git a/wk4/my_new_app/Gemfile.lock b/wk4/my_new_app/Gemfile.lock new file mode 100644 index 0000000..2ec60ab --- /dev/null +++ b/wk4/my_new_app/Gemfile.lock @@ -0,0 +1,125 @@ +GEM + remote: https://rubygems.org/ + specs: + actionmailer (4.1.1) + actionpack (= 4.1.1) + actionview (= 4.1.1) + mail (~> 2.5.4) + actionpack (4.1.1) + actionview (= 4.1.1) + activesupport (= 4.1.1) + rack (~> 1.5.2) + rack-test (~> 0.6.2) + actionview (4.1.1) + activesupport (= 4.1.1) + builder (~> 3.1) + erubis (~> 2.7.0) + activemodel (4.1.1) + activesupport (= 4.1.1) + builder (~> 3.1) + activerecord (4.1.1) + activemodel (= 4.1.1) + activesupport (= 4.1.1) + arel (~> 5.0.0) + activesupport (4.1.1) + i18n (~> 0.6, >= 0.6.9) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) + thread_safe (~> 0.1) + tzinfo (~> 1.1) + arel (5.0.1.20140414130214) + builder (3.2.2) + coffee-rails (4.0.1) + coffee-script (>= 2.2.0) + railties (>= 4.0.0, < 5.0) + coffee-script (2.2.0) + coffee-script-source + execjs + coffee-script-source (1.7.0) + erubis (2.7.0) + execjs (2.2.0) + hike (1.2.3) + i18n (0.6.9) + jbuilder (2.1.0) + activesupport (>= 3.0.0, < 5) + multi_json (~> 1.2) + jquery-rails (3.1.0) + railties (>= 3.0, < 5.0) + thor (>= 0.14, < 2.0) + json (1.8.1) + mail (2.5.4) + mime-types (~> 1.16) + treetop (~> 1.4.8) + mime-types (1.25.1) + minitest (5.3.4) + multi_json (1.10.1) + polyglot (0.3.5) + rack (1.5.2) + rack-test (0.6.2) + rack (>= 1.0) + rails (4.1.1) + actionmailer (= 4.1.1) + actionpack (= 4.1.1) + actionview (= 4.1.1) + activemodel (= 4.1.1) + activerecord (= 4.1.1) + activesupport (= 4.1.1) + bundler (>= 1.3.0, < 2.0) + railties (= 4.1.1) + sprockets-rails (~> 2.0) + railties (4.1.1) + actionpack (= 4.1.1) + activesupport (= 4.1.1) + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (10.3.2) + rdoc (4.1.1) + json (~> 1.4) + sass (3.2.19) + sass-rails (4.0.3) + railties (>= 4.0.0, < 5.0) + sass (~> 3.2.0) + sprockets (~> 2.8, <= 2.11.0) + sprockets-rails (~> 2.0) + sdoc (0.4.0) + json (~> 1.8) + rdoc (~> 4.0, < 5.0) + spring (1.1.3) + sprockets (2.11.0) + hike (~> 1.2) + multi_json (~> 1.0) + rack (~> 1.0) + tilt (~> 1.1, != 1.3.0) + sprockets-rails (2.1.3) + actionpack (>= 3.0) + activesupport (>= 3.0) + sprockets (~> 2.8) + sqlite3 (1.3.9) + thor (0.19.1) + thread_safe (0.3.4) + tilt (1.4.1) + treetop (1.4.15) + polyglot + polyglot (>= 0.3.1) + turbolinks (2.2.2) + coffee-rails + tzinfo (1.2.1) + thread_safe (~> 0.1) + uglifier (2.5.0) + execjs (>= 0.3.0) + json (>= 1.8.0) + +PLATFORMS + ruby + +DEPENDENCIES + coffee-rails (~> 4.0.0) + jbuilder (~> 2.0) + jquery-rails + rails (= 4.1.1) + sass-rails (~> 4.0.3) + sdoc (~> 0.4.0) + spring + sqlite3 + turbolinks + uglifier (>= 1.3.0) diff --git a/wk4/my_new_app/README.rdoc b/wk4/my_new_app/README.rdoc new file mode 100644 index 0000000..dd4e97e --- /dev/null +++ b/wk4/my_new_app/README.rdoc @@ -0,0 +1,28 @@ +== README + +This README would normally document whatever steps are necessary to get the +application up and running. + +Things you may want to cover: + +* Ruby version + +* System dependencies + +* Configuration + +* Database creation + +* Database initialization + +* How to run the test suite + +* Services (job queues, cache servers, search engines, etc.) + +* Deployment instructions + +* ... + + +Please feel free to use a different markup language if you do not plan to run +rake doc:app. diff --git a/wk4/my_new_app/Rakefile b/wk4/my_new_app/Rakefile new file mode 100644 index 0000000..ba6b733 --- /dev/null +++ b/wk4/my_new_app/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require File.expand_path('../config/application', __FILE__) + +Rails.application.load_tasks diff --git a/wk4/my_new_app/app/assets/images/.keep b/wk4/my_new_app/app/assets/images/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/my_new_app/app/assets/javascripts/application.js b/wk4/my_new_app/app/assets/javascripts/application.js new file mode 100644 index 0000000..d6925fa --- /dev/null +++ b/wk4/my_new_app/app/assets/javascripts/application.js @@ -0,0 +1,16 @@ +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, +// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// compiled file. +// +// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details +// about supported directives. +// +//= require jquery +//= require jquery_ujs +//= require turbolinks +//= require_tree . diff --git a/wk4/my_new_app/app/assets/javascripts/books.js.coffee b/wk4/my_new_app/app/assets/javascripts/books.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/wk4/my_new_app/app/assets/javascripts/books.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/wk4/my_new_app/app/assets/stylesheets/application.css b/wk4/my_new_app/app/assets/stylesheets/application.css new file mode 100644 index 0000000..a443db3 --- /dev/null +++ b/wk4/my_new_app/app/assets/stylesheets/application.css @@ -0,0 +1,15 @@ +/* + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, + * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the bottom of the + * compiled file so the styles you add here take precedence over styles defined in any styles + * defined in the other CSS/SCSS files in this directory. It is generally better to create a new + * file per style scope. + * + *= require_tree . + *= require_self + */ diff --git a/wk4/my_new_app/app/assets/stylesheets/books.css.scss b/wk4/my_new_app/app/assets/stylesheets/books.css.scss new file mode 100644 index 0000000..9fab565 --- /dev/null +++ b/wk4/my_new_app/app/assets/stylesheets/books.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Books controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/wk4/my_new_app/app/assets/stylesheets/scaffolds.css.scss b/wk4/my_new_app/app/assets/stylesheets/scaffolds.css.scss new file mode 100644 index 0000000..6ec6a8f --- /dev/null +++ b/wk4/my_new_app/app/assets/stylesheets/scaffolds.css.scss @@ -0,0 +1,69 @@ +body { + background-color: #fff; + color: #333; + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +p, ol, ul, td { + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +pre { + background-color: #eee; + padding: 10px; + font-size: 11px; +} + +a { + color: #000; + &:visited { + color: #666; + } + &:hover { + color: #fff; + background-color: #000; + } +} + +div { + &.field, &.actions { + margin-bottom: 10px; + } +} + +#notice { + color: green; +} + +.field_with_errors { + padding: 2px; + background-color: red; + display: table; +} + +#error_explanation { + width: 450px; + border: 2px solid red; + padding: 7px; + padding-bottom: 0; + margin-bottom: 20px; + background-color: #f0f0f0; + h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px; + margin-bottom: 0px; + background-color: #c00; + color: #fff; + } + ul li { + font-size: 12px; + list-style: square; + } +} diff --git a/wk4/my_new_app/app/controllers/application_controller.rb b/wk4/my_new_app/app/controllers/application_controller.rb new file mode 100644 index 0000000..d83690e --- /dev/null +++ b/wk4/my_new_app/app/controllers/application_controller.rb @@ -0,0 +1,5 @@ +class ApplicationController < ActionController::Base + # Prevent CSRF attacks by raising an exception. + # For APIs, you may want to use :null_session instead. + protect_from_forgery with: :exception +end diff --git a/wk4/my_new_app/app/controllers/books_controller.rb b/wk4/my_new_app/app/controllers/books_controller.rb new file mode 100644 index 0000000..24a0c52 --- /dev/null +++ b/wk4/my_new_app/app/controllers/books_controller.rb @@ -0,0 +1,74 @@ +class BooksController < ApplicationController + before_action :set_book, only: [:show, :edit, :update, :destroy] + + # GET /books + # GET /books.json + def index + @books = Book.all + end + + # GET /books/1 + # GET /books/1.json + def show + end + + # GET /books/new + def new + @book = Book.new + end + + # GET /books/1/edit + def edit + end + + # POST /books + # POST /books.json + def create + @book = Book.new(book_params) + + respond_to do |format| + if @book.save + format.html { redirect_to @book, notice: 'Book was successfully created.' } + format.json { render :show, status: :created, location: @book } + else + format.html { render :new } + format.json { render json: @book.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /books/1 + # PATCH/PUT /books/1.json + def update + respond_to do |format| + if @book.update(book_params) + format.html { redirect_to @book, notice: 'Book was successfully updated.' } + format.json { render :show, status: :ok, location: @book } + else + format.html { render :edit } + format.json { render json: @book.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /books/1 + # DELETE /books/1.json + def destroy + @book.destroy + respond_to do |format| + format.html { redirect_to books_url, notice: 'Book was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_book + @book = Book.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def book_params + params.require(:book).permit(:author, :title, :abstract) + end +end diff --git a/wk4/my_new_app/app/controllers/concerns/.keep b/wk4/my_new_app/app/controllers/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/my_new_app/app/helpers/application_helper.rb b/wk4/my_new_app/app/helpers/application_helper.rb new file mode 100644 index 0000000..de6be79 --- /dev/null +++ b/wk4/my_new_app/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/wk4/my_new_app/app/helpers/books_helper.rb b/wk4/my_new_app/app/helpers/books_helper.rb new file mode 100644 index 0000000..4b9311e --- /dev/null +++ b/wk4/my_new_app/app/helpers/books_helper.rb @@ -0,0 +1,2 @@ +module BooksHelper +end diff --git a/wk4/my_new_app/app/mailers/.keep b/wk4/my_new_app/app/mailers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/my_new_app/app/models/.keep b/wk4/my_new_app/app/models/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/my_new_app/app/models/book.rb b/wk4/my_new_app/app/models/book.rb new file mode 100644 index 0000000..6f68b44 --- /dev/null +++ b/wk4/my_new_app/app/models/book.rb @@ -0,0 +1,2 @@ +class Book < ActiveRecord::Base +end diff --git a/wk4/my_new_app/app/models/concerns/.keep b/wk4/my_new_app/app/models/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/my_new_app/app/views/books/_form.html.erb b/wk4/my_new_app/app/views/books/_form.html.erb new file mode 100644 index 0000000..85c0ab0 --- /dev/null +++ b/wk4/my_new_app/app/views/books/_form.html.erb @@ -0,0 +1,29 @@ +<%= form_for(@book) do |f| %> + <% if @book.errors.any? %> +
+

<%= pluralize(@book.errors.count, "error") %> prohibited this book from being saved:

+ +
    + <% @book.errors.full_messages.each do |message| %> +
  • <%= message %>
  • + <% end %> +
+
+ <% end %> + +
+ <%= f.label :author %>
+ <%= f.text_field :author %> +
+
+ <%= f.label :title %>
+ <%= f.text_field :title %> +
+
+ <%= f.label :abstract %>
+ <%= f.text_area :abstract %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/wk4/my_new_app/app/views/books/edit.html.erb b/wk4/my_new_app/app/views/books/edit.html.erb new file mode 100644 index 0000000..a907cb4 --- /dev/null +++ b/wk4/my_new_app/app/views/books/edit.html.erb @@ -0,0 +1,6 @@ +

Editing book

+ +<%= render 'form' %> + +<%= link_to 'Show', @book %> | +<%= link_to 'Back', books_path %> diff --git a/wk4/my_new_app/app/views/books/index.html.erb b/wk4/my_new_app/app/views/books/index.html.erb new file mode 100644 index 0000000..be95113 --- /dev/null +++ b/wk4/my_new_app/app/views/books/index.html.erb @@ -0,0 +1,29 @@ +

Listing books

+ + + + + + + + + + + + + <% @books.each do |book| %> + + + + + + + + + <% end %> + +
AuthorTitleAbstract
<%= book.author %><%= book.title %><%= book.abstract %><%= link_to 'Show', book %><%= link_to 'Edit', edit_book_path(book) %><%= link_to 'Destroy', book, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Book', new_book_path %> diff --git a/wk4/my_new_app/app/views/books/index.json.jbuilder b/wk4/my_new_app/app/views/books/index.json.jbuilder new file mode 100644 index 0000000..ebd594c --- /dev/null +++ b/wk4/my_new_app/app/views/books/index.json.jbuilder @@ -0,0 +1,4 @@ +json.array!(@books) do |book| + json.extract! book, :id, :author, :title, :abstract + json.url book_url(book, format: :json) +end diff --git a/wk4/my_new_app/app/views/books/new.html.erb b/wk4/my_new_app/app/views/books/new.html.erb new file mode 100644 index 0000000..c9042b2 --- /dev/null +++ b/wk4/my_new_app/app/views/books/new.html.erb @@ -0,0 +1,5 @@ +

New book

+ +<%= render 'form' %> + +<%= link_to 'Back', books_path %> diff --git a/wk4/my_new_app/app/views/books/show.html.erb b/wk4/my_new_app/app/views/books/show.html.erb new file mode 100644 index 0000000..72d6271 --- /dev/null +++ b/wk4/my_new_app/app/views/books/show.html.erb @@ -0,0 +1,19 @@ +

<%= notice %>

+ +

+ Author: + <%= @book.author %> +

+ +

+ Title: + <%= @book.title %> +

+ +

+ Abstract: + <%= @book.abstract %> +

+ +<%= link_to 'Edit', edit_book_path(@book) %> | +<%= link_to 'Back', books_path %> diff --git a/wk4/my_new_app/app/views/books/show.json.jbuilder b/wk4/my_new_app/app/views/books/show.json.jbuilder new file mode 100644 index 0000000..b7cf8b6 --- /dev/null +++ b/wk4/my_new_app/app/views/books/show.json.jbuilder @@ -0,0 +1 @@ +json.extract! @book, :id, :author, :title, :abstract, :created_at, :updated_at diff --git a/wk4/my_new_app/app/views/layouts/application.html.erb b/wk4/my_new_app/app/views/layouts/application.html.erb new file mode 100644 index 0000000..20915a0 --- /dev/null +++ b/wk4/my_new_app/app/views/layouts/application.html.erb @@ -0,0 +1,14 @@ + + + + MyNewApp + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> + <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> + <%= csrf_meta_tags %> + + + +<%= yield %> + + + diff --git a/wk4/my_new_app/bin/bundle b/wk4/my_new_app/bin/bundle new file mode 100755 index 0000000..66e9889 --- /dev/null +++ b/wk4/my_new_app/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +load Gem.bin_path('bundler', 'bundle') diff --git a/wk4/my_new_app/bin/rails b/wk4/my_new_app/bin/rails new file mode 100755 index 0000000..7feb6a3 --- /dev/null +++ b/wk4/my_new_app/bin/rails @@ -0,0 +1,8 @@ +#!/usr/bin/env ruby +begin + load File.expand_path("../spring", __FILE__) +rescue LoadError +end +APP_PATH = File.expand_path('../../config/application', __FILE__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/wk4/my_new_app/bin/rake b/wk4/my_new_app/bin/rake new file mode 100755 index 0000000..8017a02 --- /dev/null +++ b/wk4/my_new_app/bin/rake @@ -0,0 +1,8 @@ +#!/usr/bin/env ruby +begin + load File.expand_path("../spring", __FILE__) +rescue LoadError +end +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/wk4/my_new_app/bin/spring b/wk4/my_new_app/bin/spring new file mode 100755 index 0000000..253ec37 --- /dev/null +++ b/wk4/my_new_app/bin/spring @@ -0,0 +1,18 @@ +#!/usr/bin/env ruby + +# This file loads spring without using Bundler, in order to be fast +# It gets overwritten when you run the `spring binstub` command + +unless defined?(Spring) + require "rubygems" + require "bundler" + + if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ spring \((.*?)\)$.*?^$/m) + ENV["GEM_PATH"] = ([Bundler.bundle_path.to_s] + Gem.path).join(File::PATH_SEPARATOR) + ENV["GEM_HOME"] = "" + Gem.paths = ENV + + gem "spring", match[1] + require "spring/binstub" + end +end diff --git a/wk4/my_new_app/config.rb b/wk4/my_new_app/config.rb new file mode 100644 index 0000000..e69de29 diff --git a/wk4/my_new_app/config.ru b/wk4/my_new_app/config.ru new file mode 100644 index 0000000..5bc2a61 --- /dev/null +++ b/wk4/my_new_app/config.ru @@ -0,0 +1,4 @@ +# This file is used by Rack-based servers to start the application. + +require ::File.expand_path('../config/environment', __FILE__) +run Rails.application diff --git a/wk4/my_new_app/config/application.rb b/wk4/my_new_app/config/application.rb new file mode 100644 index 0000000..d216858 --- /dev/null +++ b/wk4/my_new_app/config/application.rb @@ -0,0 +1,23 @@ +require File.expand_path('../boot', __FILE__) + +require 'rails/all' + +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(*Rails.groups) + +module MyNewApp + class Application < Rails::Application + # Settings in config/environments/* take precedence over those specified here. + # Application configuration should go into files in config/initializers + # -- all .rb files in that directory are automatically loaded. + + # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. + # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. + # config.time_zone = 'Central Time (US & Canada)' + + # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. + # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] + # config.i18n.default_locale = :de + end +end diff --git a/wk4/my_new_app/config/boot.rb b/wk4/my_new_app/config/boot.rb new file mode 100644 index 0000000..5e5f0c1 --- /dev/null +++ b/wk4/my_new_app/config/boot.rb @@ -0,0 +1,4 @@ +# Set up gems listed in the Gemfile. +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) + +require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) diff --git a/wk4/my_new_app/config/database.yml b/wk4/my_new_app/config/database.yml new file mode 100644 index 0000000..1c1a37c --- /dev/null +++ b/wk4/my_new_app/config/database.yml @@ -0,0 +1,25 @@ +# SQLite version 3.x +# gem install sqlite3 +# +# Ensure the SQLite 3 gem is defined in your Gemfile +# gem 'sqlite3' +# +default: &default + adapter: sqlite3 + pool: 5 + timeout: 5000 + +development: + <<: *default + database: db/development.sqlite3 + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: db/test.sqlite3 + +production: + <<: *default + database: db/production.sqlite3 diff --git a/wk4/my_new_app/config/environment.rb b/wk4/my_new_app/config/environment.rb new file mode 100644 index 0000000..ee8d90d --- /dev/null +++ b/wk4/my_new_app/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require File.expand_path('../application', __FILE__) + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/wk4/my_new_app/config/environments/development.rb b/wk4/my_new_app/config/environments/development.rb new file mode 100644 index 0000000..ddf0e90 --- /dev/null +++ b/wk4/my_new_app/config/environments/development.rb @@ -0,0 +1,37 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + # Debug mode disables concatenation and preprocessing of assets. + # This option may cause significant delays in view rendering with a large + # number of complex assets. + config.assets.debug = true + + # Adds additional error checking when serving assets at runtime. + # Checks for improperly declared sprockets dependencies. + # Raises helpful error messages. + config.assets.raise_runtime_errors = true + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true +end diff --git a/wk4/my_new_app/config/environments/production.rb b/wk4/my_new_app/config/environments/production.rb new file mode 100644 index 0000000..47d3553 --- /dev/null +++ b/wk4/my_new_app/config/environments/production.rb @@ -0,0 +1,83 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Enable Rack::Cache to put a simple HTTP cache in front of your application + # Add `rack-cache` to your Gemfile before enabling this. + # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid. + # config.action_dispatch.rack_cache = true + + # Disable Rails's static asset server (Apache or nginx will already do this). + config.serve_static_assets = false + + # Compress JavaScripts and CSS. + config.assets.js_compressor = :uglifier + # config.assets.css_compressor = :sass + + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = false + + # Generate digests for assets URLs. + config.assets.digest = true + + # Version of your assets, change this if you want to expire all your assets. + config.assets.version = '1.0' + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Set to :debug to see everything in the log. + config.log_level = :info + + # Prepend all log lines with the following tags. + # config.log_tags = [ :subdomain, :uuid ] + + # Use a different logger for distributed setups. + # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = "http://assets.example.com" + + # Precompile additional assets. + # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. + # config.assets.precompile += %w( search.js ) + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Disable automatic flushing of the log to improve performance. + # config.autoflush_log = false + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false +end diff --git a/wk4/my_new_app/config/environments/test.rb b/wk4/my_new_app/config/environments/test.rb new file mode 100644 index 0000000..053f5b6 --- /dev/null +++ b/wk4/my_new_app/config/environments/test.rb @@ -0,0 +1,39 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # The test environment is used exclusively to run your application's + # test suite. You never need to work with it otherwise. Remember that + # your test database is "scratch space" for the test suite and is wiped + # and recreated between test runs. Don't rely on the data there! + config.cache_classes = true + + # Do not eager load code on boot. This avoids loading your whole application + # just for the purpose of running a single test. If you are using a tool that + # preloads Rails for running tests, you may have to set it to true. + config.eager_load = false + + # Configure static asset server for tests with Cache-Control for performance. + config.serve_static_assets = true + config.static_cache_control = 'public, max-age=3600' + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Raise exceptions instead of rendering exception templates. + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true +end diff --git a/wk4/my_new_app/config/initializers/backtrace_silencers.rb b/wk4/my_new_app/config/initializers/backtrace_silencers.rb new file mode 100644 index 0000000..59385cd --- /dev/null +++ b/wk4/my_new_app/config/initializers/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# Rails.backtrace_cleaner.remove_silencers! diff --git a/wk4/my_new_app/config/initializers/cookies_serializer.rb b/wk4/my_new_app/config/initializers/cookies_serializer.rb new file mode 100644 index 0000000..7a06a89 --- /dev/null +++ b/wk4/my_new_app/config/initializers/cookies_serializer.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +Rails.application.config.action_dispatch.cookies_serializer = :json \ No newline at end of file diff --git a/wk4/my_new_app/config/initializers/filter_parameter_logging.rb b/wk4/my_new_app/config/initializers/filter_parameter_logging.rb new file mode 100644 index 0000000..4a994e1 --- /dev/null +++ b/wk4/my_new_app/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Configure sensitive parameters which will be filtered from the log file. +Rails.application.config.filter_parameters += [:password] diff --git a/wk4/my_new_app/config/initializers/inflections.rb b/wk4/my_new_app/config/initializers/inflections.rb new file mode 100644 index 0000000..ac033bf --- /dev/null +++ b/wk4/my_new_app/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/wk4/my_new_app/config/initializers/mime_types.rb b/wk4/my_new_app/config/initializers/mime_types.rb new file mode 100644 index 0000000..dc18996 --- /dev/null +++ b/wk4/my_new_app/config/initializers/mime_types.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf diff --git a/wk4/my_new_app/config/initializers/session_store.rb b/wk4/my_new_app/config/initializers/session_store.rb new file mode 100644 index 0000000..2da1124 --- /dev/null +++ b/wk4/my_new_app/config/initializers/session_store.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +Rails.application.config.session_store :cookie_store, key: '_my_new_app_session' diff --git a/wk4/my_new_app/config/initializers/wrap_parameters.rb b/wk4/my_new_app/config/initializers/wrap_parameters.rb new file mode 100644 index 0000000..33725e9 --- /dev/null +++ b/wk4/my_new_app/config/initializers/wrap_parameters.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. + +# This file contains settings for ActionController::ParamsWrapper which +# is enabled by default. + +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. +ActiveSupport.on_load(:action_controller) do + wrap_parameters format: [:json] if respond_to?(:wrap_parameters) +end + +# To enable root element in JSON for ActiveRecord objects. +# ActiveSupport.on_load(:active_record) do +# self.include_root_in_json = true +# end diff --git a/wk4/my_new_app/config/locales/en.yml b/wk4/my_new_app/config/locales/en.yml new file mode 100644 index 0000000..0653957 --- /dev/null +++ b/wk4/my_new_app/config/locales/en.yml @@ -0,0 +1,23 @@ +# Files in the config/locales directory are used for internationalization +# and are automatically loaded by Rails. If you want to use locales other +# than English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t 'hello' +# +# In views, this is aliased to just `t`: +# +# <%= t('hello') %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# To learn more, please read the Rails Internationalization guide +# available at http://guides.rubyonrails.org/i18n.html. + +en: + hello: "Hello world" diff --git a/wk4/my_new_app/config/routes.rb b/wk4/my_new_app/config/routes.rb new file mode 100644 index 0000000..f075ae6 --- /dev/null +++ b/wk4/my_new_app/config/routes.rb @@ -0,0 +1,58 @@ +Rails.application.routes.draw do + resources :books + + # The priority is based upon order of creation: first created -> highest priority. + # See how all your routes lay out with "rake routes". + + # You can have the root of your site routed with "root" + # root 'welcome#index' + + # Example of regular route: + # get 'products/:id' => 'catalog#view' + + # Example of named route that can be invoked with purchase_url(id: product.id) + # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase + + # Example resource route (maps HTTP verbs to controller actions automatically): + # resources :products + + # Example resource route with options: + # resources :products do + # member do + # get 'short' + # post 'toggle' + # end + # + # collection do + # get 'sold' + # end + # end + + # Example resource route with sub-resources: + # resources :products do + # resources :comments, :sales + # resource :seller + # end + + # Example resource route with more complex sub-resources: + # resources :products do + # resources :comments + # resources :sales do + # get 'recent', on: :collection + # end + # end + + # Example resource route with concerns: + # concern :toggleable do + # post 'toggle' + # end + # resources :posts, concerns: :toggleable + # resources :photos, concerns: :toggleable + + # Example resource route within a namespace: + # namespace :admin do + # # Directs /admin/products/* to Admin::ProductsController + # # (app/controllers/admin/products_controller.rb) + # resources :products + # end +end diff --git a/wk4/my_new_app/config/secrets.yml b/wk4/my_new_app/config/secrets.yml new file mode 100644 index 0000000..ff674b8 --- /dev/null +++ b/wk4/my_new_app/config/secrets.yml @@ -0,0 +1,22 @@ +# Be sure to restart your server when you modify this file. + +# Your secret key is used for verifying the integrity of signed cookies. +# If you change this key, all old signed cookies will become invalid! + +# Make sure the secret is at least 30 characters and all random, +# no regular words or you'll be exposed to dictionary attacks. +# You can use `rake secret` to generate a secure secret key. + +# Make sure the secrets in this file are kept private +# if you're sharing your code publicly. + +development: + secret_key_base: 406d881064cace54c2f5e43707a710a1a933476f8c6cee1ef1cdb06952a0da4616e17964e088664f2e8a78782522da660b4af4fd358164b609e57f4aef07a1ec + +test: + secret_key_base: c81cf59842fdef24b8ec5c5bdcb71cdc7070afb23606a5c9f9d2e444a8fe85557b409bd184e9bb46482d614741270191ec4dba070f408748ece86f462bd4b8d5 + +# Do not keep production secrets in the repository, +# instead read values from the environment. +production: + secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> diff --git a/wk4/my_new_app/db/migrate/20140611014121_create_books.rb b/wk4/my_new_app/db/migrate/20140611014121_create_books.rb new file mode 100644 index 0000000..b0155d7 --- /dev/null +++ b/wk4/my_new_app/db/migrate/20140611014121_create_books.rb @@ -0,0 +1,11 @@ +class CreateBooks < ActiveRecord::Migration + def change + create_table :books do |t| + t.string :author + t.string :title + t.text :abstract + + t.timestamps + end + end +end diff --git a/wk4/my_new_app/db/schema.rb b/wk4/my_new_app/db/schema.rb new file mode 100644 index 0000000..c695a09 --- /dev/null +++ b/wk4/my_new_app/db/schema.rb @@ -0,0 +1,24 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20140611014121) do + + create_table "books", force: true do |t| + t.string "author" + t.string "title" + t.text "abstract" + t.datetime "created_at" + t.datetime "updated_at" + end + +end diff --git a/wk4/my_new_app/db/seeds.rb b/wk4/my_new_app/db/seeds.rb new file mode 100644 index 0000000..4edb1e8 --- /dev/null +++ b/wk4/my_new_app/db/seeds.rb @@ -0,0 +1,7 @@ +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). +# +# Examples: +# +# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) +# Mayor.create(name: 'Emanuel', city: cities.first) diff --git a/wk4/my_new_app/lib/assets/.keep b/wk4/my_new_app/lib/assets/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/my_new_app/lib/tasks/.keep b/wk4/my_new_app/lib/tasks/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/my_new_app/log/.keep b/wk4/my_new_app/log/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/my_new_app/public/404.html b/wk4/my_new_app/public/404.html new file mode 100644 index 0000000..b612547 --- /dev/null +++ b/wk4/my_new_app/public/404.html @@ -0,0 +1,67 @@ + + + + The page you were looking for doesn't exist (404) + + + + + + +
+
+

The page you were looking for doesn't exist.

+

You may have mistyped the address or the page may have moved.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/wk4/my_new_app/public/422.html b/wk4/my_new_app/public/422.html new file mode 100644 index 0000000..a21f82b --- /dev/null +++ b/wk4/my_new_app/public/422.html @@ -0,0 +1,67 @@ + + + + The change you wanted was rejected (422) + + + + + + +
+
+

The change you wanted was rejected.

+

Maybe you tried to change something you didn't have access to.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/wk4/my_new_app/public/500.html b/wk4/my_new_app/public/500.html new file mode 100644 index 0000000..061abc5 --- /dev/null +++ b/wk4/my_new_app/public/500.html @@ -0,0 +1,66 @@ + + + + We're sorry, but something went wrong (500) + + + + + + +
+
+

We're sorry, but something went wrong.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/wk4/my_new_app/public/favicon.ico b/wk4/my_new_app/public/favicon.ico new file mode 100644 index 0000000..e69de29 diff --git a/wk4/my_new_app/public/robots.txt b/wk4/my_new_app/public/robots.txt new file mode 100644 index 0000000..3c9c7c0 --- /dev/null +++ b/wk4/my_new_app/public/robots.txt @@ -0,0 +1,5 @@ +# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file +# +# To ban all spiders from the entire site uncomment the next two lines: +# User-agent: * +# Disallow: / diff --git a/wk4/my_new_app/public/testing.txt b/wk4/my_new_app/public/testing.txt new file mode 100644 index 0000000..bdc78bf --- /dev/null +++ b/wk4/my_new_app/public/testing.txt @@ -0,0 +1 @@ +This is a test - testing 1 2 3! \ No newline at end of file diff --git a/wk4/my_new_app/test/controllers/.keep b/wk4/my_new_app/test/controllers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/my_new_app/test/controllers/books_controller_test.rb b/wk4/my_new_app/test/controllers/books_controller_test.rb new file mode 100644 index 0000000..54e2803 --- /dev/null +++ b/wk4/my_new_app/test/controllers/books_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class BooksControllerTest < ActionController::TestCase + setup do + @book = books(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:books) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create book" do + assert_difference('Book.count') do + post :create, book: { abstract: @book.abstract, author: @book.author, title: @book.title } + end + + assert_redirected_to book_path(assigns(:book)) + end + + test "should show book" do + get :show, id: @book + assert_response :success + end + + test "should get edit" do + get :edit, id: @book + assert_response :success + end + + test "should update book" do + patch :update, id: @book, book: { abstract: @book.abstract, author: @book.author, title: @book.title } + assert_redirected_to book_path(assigns(:book)) + end + + test "should destroy book" do + assert_difference('Book.count', -1) do + delete :destroy, id: @book + end + + assert_redirected_to books_path + end +end diff --git a/wk4/my_new_app/test/fixtures/.keep b/wk4/my_new_app/test/fixtures/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/my_new_app/test/fixtures/books.yml b/wk4/my_new_app/test/fixtures/books.yml new file mode 100644 index 0000000..6c119d9 --- /dev/null +++ b/wk4/my_new_app/test/fixtures/books.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + author: MyString + title: MyString + abstract: MyText + +two: + author: MyString + title: MyString + abstract: MyText diff --git a/wk4/my_new_app/test/helpers/.keep b/wk4/my_new_app/test/helpers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/my_new_app/test/helpers/books_helper_test.rb b/wk4/my_new_app/test/helpers/books_helper_test.rb new file mode 100644 index 0000000..b4547f9 --- /dev/null +++ b/wk4/my_new_app/test/helpers/books_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class BooksHelperTest < ActionView::TestCase +end diff --git a/wk4/my_new_app/test/integration/.keep b/wk4/my_new_app/test/integration/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/my_new_app/test/mailers/.keep b/wk4/my_new_app/test/mailers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/my_new_app/test/models/.keep b/wk4/my_new_app/test/models/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/my_new_app/test/models/book_test.rb b/wk4/my_new_app/test/models/book_test.rb new file mode 100644 index 0000000..e48079d --- /dev/null +++ b/wk4/my_new_app/test/models/book_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class BookTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/wk4/my_new_app/test/test_helper.rb b/wk4/my_new_app/test/test_helper.rb new file mode 100644 index 0000000..bf95f81 --- /dev/null +++ b/wk4/my_new_app/test/test_helper.rb @@ -0,0 +1,13 @@ +ENV['RAILS_ENV'] ||= 'test' +require File.expand_path('../../config/environment', __FILE__) +require 'rails/test_help' + +class ActiveSupport::TestCase + # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. + # + # Note: You'll currently still have to declare fixtures explicitly in integration tests + # -- they do not yet inherit this setting + fixtures :all + + # Add more helper methods to be used by all tests here... +end diff --git a/wk4/my_new_app/vendor/assets/javascripts/.keep b/wk4/my_new_app/vendor/assets/javascripts/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/my_new_app/vendor/assets/stylesheets/.keep b/wk4/my_new_app/vendor/assets/stylesheets/.keep new file mode 100644 index 0000000..e69de29 diff --git a/wk4/tuesday b/wk4/tuesday new file mode 100644 index 0000000..e69de29 From 34a92f72f5d99fe76b0ae9d39ae38cce2d4be882 Mon Sep 17 00:00:00 2001 From: Paul Mumma Date: Wed, 11 Jun 2014 22:17:20 -0700 Subject: [PATCH 06/14] step 1 complete --- wk4/PaulMidterm/lib/gameplay.rb | 20 ++++++++++ wk4/PaulMidterm/lib/organizer.rb | 10 +++++ wk4/PaulMidterm/lib/players.rb | 8 ++++ wk4/PaulMidterm/main.rb | 66 ++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+) create mode 100644 wk4/PaulMidterm/lib/gameplay.rb create mode 100644 wk4/PaulMidterm/lib/organizer.rb create mode 100644 wk4/PaulMidterm/lib/players.rb create mode 100644 wk4/PaulMidterm/main.rb diff --git a/wk4/PaulMidterm/lib/gameplay.rb b/wk4/PaulMidterm/lib/gameplay.rb new file mode 100644 index 0000000..3b62880 --- /dev/null +++ b/wk4/PaulMidterm/lib/gameplay.rb @@ -0,0 +1,20 @@ +#require lib/organizer? + +class Game + + attr_accessor :participant_count, :chosen_topic, :players + + def initialize(participant_count, chosen_topic, players) + @participant_count = participant_count + @chosen_topic = chosen_topic + @players = [] + end + +def start_playing + puts "Your chosen topic is #{@chosen_topic}" + puts "There are #{@participant_count} players in this game" + puts"Now I would send an SMSS" +end + + +end diff --git a/wk4/PaulMidterm/lib/organizer.rb b/wk4/PaulMidterm/lib/organizer.rb new file mode 100644 index 0000000..74fb878 --- /dev/null +++ b/wk4/PaulMidterm/lib/organizer.rb @@ -0,0 +1,10 @@ +class Organizer + +attr_accessor :name, :organizer_phone_number + +def initialize(name, organizer_phone_number) + @name = name + @organizer_phone_number = organizer_phone_number + end + +end diff --git a/wk4/PaulMidterm/lib/players.rb b/wk4/PaulMidterm/lib/players.rb new file mode 100644 index 0000000..bf304bb --- /dev/null +++ b/wk4/PaulMidterm/lib/players.rb @@ -0,0 +1,8 @@ +class Player + attr_accessor :name, :phone_number + + def initialize(name, phone_number) + @name = name + @phone_number = phone_number + end +end diff --git a/wk4/PaulMidterm/main.rb b/wk4/PaulMidterm/main.rb new file mode 100644 index 0000000..e76f2f7 --- /dev/null +++ b/wk4/PaulMidterm/main.rb @@ -0,0 +1,66 @@ +# Paul Mumma Midterm - Main + +#Welcome the game organizer + +require_relative 'lib/players' +require_relative 'lib/organizer' +require_relative 'lib/gameplay' + +def create_player +puts "---- New Player ----" +puts "Player name: " +name = gets.strip +puts "Player's phone number: " +# HAVE TO FIND A WAY TO CHECK AND CLEAN INPUT +phone_number=gets.strip + +Player.new(name,phone_number) +end + + +puts +puts "*=*=*=*=*=*= Welcome to Double-Blind Twenty Questions! *=*=*=*=*=*=" +puts +puts "What is your name?" +#grab organizer's name +organizer_name = gets.chomp +puts "What is your phone number?" +#grab organizer's phone number +organizer_phone_number = gets.to_i +organizer = Organizer.new(organizer_name, organizer_phone_number) + +#Ask the organizer to choose a set of roles for the game +puts "How many players (other than you) are going to play Double-Blind Twenty Questions?" +# TO DO: validate that input is a number +participant_count = gets.to_i + +#Asks organizer to choose what category the game will draw from. +#TO DO: allow organizer to create his own category OR combine existing categories +puts "Which category do you want to use to assign roles to players? Enter a number to choose one of the following:" +puts +puts "(1) Famous Greeks and Romans \n(2) Children's Book Characters \n(3) Silicon Valley Who's-Who" +chosen_topic = gets.to_i + +game=Game.new(participant_count, chosen_topic, []) + +#Creates players and puts them into the player array +0.upto(participant_count-1) do |participant| + player = create_player + game.players[participant] = player + puts "#{player.name} added successfully" +end + +while 1==1 +puts "Ready to Play? (y/n)" +answer = gets.chomp.downcase +if answer=="y" + puts "OK - sending messages now. Have fun!" + game.start_playing + exit +elsif answer == "n" + puts "No problem - just exit the program and start over" + exit +else + puts "Please enter a valid answer ('y' or 'n')" +end +end From a4e2191e01cc383412280b3e3ea76e2ec8d50899 Mon Sep 17 00:00:00 2001 From: Paul Mumma Date: Wed, 11 Jun 2014 22:49:57 -0700 Subject: [PATCH 07/14] progress --- wk4/PaulMidterm/lib/gameplay.rb | 18 +++++++++++++++--- wk4/PaulMidterm/lib/players.rb | 21 +++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/wk4/PaulMidterm/lib/gameplay.rb b/wk4/PaulMidterm/lib/gameplay.rb index 3b62880..879ce81 100644 --- a/wk4/PaulMidterm/lib/gameplay.rb +++ b/wk4/PaulMidterm/lib/gameplay.rb @@ -10,11 +10,23 @@ def initialize(participant_count, chosen_topic, players) @players = [] end +#Experimental method 2 def start_playing - puts "Your chosen topic is #{@chosen_topic}" - puts "There are #{@participant_count} players in this game" - puts"Now I would send an SMSS" + @players.each do |player| + puts player.name + puts player.phone_number + player.send_Twilio_SMS + end + end +#This method works +# def start_playing +# puts "Your chosen topic is #{@chosen_topic}" +# puts "There are #{@participant_count} players in this game" +# puts"Now I would send an SMSS" +# end + + end diff --git a/wk4/PaulMidterm/lib/players.rb b/wk4/PaulMidterm/lib/players.rb index bf304bb..9ce27b0 100644 --- a/wk4/PaulMidterm/lib/players.rb +++ b/wk4/PaulMidterm/lib/players.rb @@ -1,3 +1,7 @@ +require 'rubygems' # not necessary with ruby 1.9 but included for completeness +require 'twilio-ruby' +require 'json' + class Player attr_accessor :name, :phone_number @@ -5,4 +9,21 @@ def initialize(name, phone_number) @name = name @phone_number = phone_number end + + def send_Twilio_SMS +# Paul's Twilio API credentials + account_sid = 'AC277cf35a20573e1d13f3c50f45b92612' + auth_token = '0379092183f9ef2732e7a08f82bb50fe' + +# set up a client to talk to the Twilio REST API + @client = Twilio::REST::Client.new account_sid, auth_token + + @client.account.messages.create({ + #FROM is from Paul's Twilio Phone number + :from => '+13129975477', + :to => "+1#{@phone_number}", + :body => 'Assigned role: Johnny Walker', + }) + end + end From cc219d072f17d1d6c729fa8cb27a2c0466edf3ef Mon Sep 17 00:00:00 2001 From: Paul Mumma Date: Wed, 11 Jun 2014 23:08:31 -0700 Subject: [PATCH 08/14] step 3 --- wk4/PaulMidterm/lib/gameplay.rb | 15 ++------------- wk4/PaulMidterm/main.rb | 6 ++++-- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/wk4/PaulMidterm/lib/gameplay.rb b/wk4/PaulMidterm/lib/gameplay.rb index 879ce81..fb100b4 100644 --- a/wk4/PaulMidterm/lib/gameplay.rb +++ b/wk4/PaulMidterm/lib/gameplay.rb @@ -4,29 +4,18 @@ class Game attr_accessor :participant_count, :chosen_topic, :players - def initialize(participant_count, chosen_topic, players) + def initialize(participant_count, chosen_topic) @participant_count = participant_count @chosen_topic = chosen_topic @players = [] end -#Experimental method 2 def start_playing @players.each do |player| - puts player.name - puts player.phone_number + puts "Sending #{player.name} an SMS with their assigned role at #{player.phone_number}" player.send_Twilio_SMS end end - -#This method works -# def start_playing -# puts "Your chosen topic is #{@chosen_topic}" -# puts "There are #{@participant_count} players in this game" -# puts"Now I would send an SMSS" -# end - - end diff --git a/wk4/PaulMidterm/main.rb b/wk4/PaulMidterm/main.rb index e76f2f7..a9d490a 100644 --- a/wk4/PaulMidterm/main.rb +++ b/wk4/PaulMidterm/main.rb @@ -41,7 +41,7 @@ def create_player puts "(1) Famous Greeks and Romans \n(2) Children's Book Characters \n(3) Silicon Valley Who's-Who" chosen_topic = gets.to_i -game=Game.new(participant_count, chosen_topic, []) +game=Game.new(participant_count, chosen_topic) #Creates players and puts them into the player array 0.upto(participant_count-1) do |participant| @@ -54,8 +54,10 @@ def create_player puts "Ready to Play? (y/n)" answer = gets.chomp.downcase if answer=="y" - puts "OK - sending messages now. Have fun!" + puts game.start_playing + puts + puts "All messages sent - now go have fun without your computer!" exit elsif answer == "n" puts "No problem - just exit the program and start over" From 01112308435a81871aed23a12fc90f8e9e90ba95 Mon Sep 17 00:00:00 2001 From: Paul Mumma Date: Wed, 11 Jun 2014 23:15:20 -0700 Subject: [PATCH 09/14] working again --- wk4/PaulMidterm/lib/gameplay.rb | 10 ++++------ wk4/PaulMidterm/lib/players.rb | 8 ++++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/wk4/PaulMidterm/lib/gameplay.rb b/wk4/PaulMidterm/lib/gameplay.rb index fb100b4..b29c101 100644 --- a/wk4/PaulMidterm/lib/gameplay.rb +++ b/wk4/PaulMidterm/lib/gameplay.rb @@ -1,5 +1,3 @@ -#require lib/organizer? - class Game attr_accessor :participant_count, :chosen_topic, :players @@ -10,12 +8,12 @@ def initialize(participant_count, chosen_topic) @players = [] end -def start_playing - @players.each do |player| + def start_playing + @players.each do |player| puts "Sending #{player.name} an SMS with their assigned role at #{player.phone_number}" player.send_Twilio_SMS - end + end -end + end end diff --git a/wk4/PaulMidterm/lib/players.rb b/wk4/PaulMidterm/lib/players.rb index 9ce27b0..c2b2ec5 100644 --- a/wk4/PaulMidterm/lib/players.rb +++ b/wk4/PaulMidterm/lib/players.rb @@ -11,13 +11,13 @@ def initialize(name, phone_number) end def send_Twilio_SMS -# Paul's Twilio API credentials + # Paul's Twilio API credentials account_sid = 'AC277cf35a20573e1d13f3c50f45b92612' auth_token = '0379092183f9ef2732e7a08f82bb50fe' - -# set up a client to talk to the Twilio REST API + + # set up a client to talk to the Twilio REST API @client = Twilio::REST::Client.new account_sid, auth_token - + @client.account.messages.create({ #FROM is from Paul's Twilio Phone number :from => '+13129975477', From d34afffceaf058424fa573203b828f283aebcd58 Mon Sep 17 00:00:00 2001 From: Paul Mumma Date: Wed, 11 Jun 2014 23:52:52 -0700 Subject: [PATCH 10/14] step4 --- wk4/PaulMidterm/lib/players.rb | 2 +- wk4/PaulMidterm/main.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/wk4/PaulMidterm/lib/players.rb b/wk4/PaulMidterm/lib/players.rb index c2b2ec5..9eae01f 100644 --- a/wk4/PaulMidterm/lib/players.rb +++ b/wk4/PaulMidterm/lib/players.rb @@ -22,7 +22,7 @@ def send_Twilio_SMS #FROM is from Paul's Twilio Phone number :from => '+13129975477', :to => "+1#{@phone_number}", - :body => 'Assigned role: Johnny Walker', + :body => 'Your assignment Johnny Walker', }) end diff --git a/wk4/PaulMidterm/main.rb b/wk4/PaulMidterm/main.rb index a9d490a..00e7c12 100644 --- a/wk4/PaulMidterm/main.rb +++ b/wk4/PaulMidterm/main.rb @@ -19,7 +19,7 @@ def create_player puts -puts "*=*=*=*=*=*= Welcome to Double-Blind Twenty Questions! *=*=*=*=*=*=" +puts "*=*=*=*=*=*= Welcome to the Automatic Charade Generator! *=*=*=*=*=*=" puts puts "What is your name?" #grab organizer's name @@ -30,13 +30,13 @@ def create_player organizer = Organizer.new(organizer_name, organizer_phone_number) #Ask the organizer to choose a set of roles for the game -puts "How many players (other than you) are going to play Double-Blind Twenty Questions?" +puts "How many players (other than you) are going to play charades?" # TO DO: validate that input is a number participant_count = gets.to_i #Asks organizer to choose what category the game will draw from. #TO DO: allow organizer to create his own category OR combine existing categories -puts "Which category do you want to use to assign roles to players? Enter a number to choose one of the following:" +puts "Which category do you want to draw from? Enter a number to choose one of the following:" puts puts "(1) Famous Greeks and Romans \n(2) Children's Book Characters \n(3) Silicon Valley Who's-Who" chosen_topic = gets.to_i @@ -57,7 +57,7 @@ def create_player puts game.start_playing puts - puts "All messages sent - now go have fun without your computer!" + puts "All messages sent - now go play charades!" exit elsif answer == "n" puts "No problem - just exit the program and start over" From f99ccf6196dd0593559c3de4632f0094047ec79c Mon Sep 17 00:00:00 2001 From: Paul Mumma Date: Thu, 12 Jun 2014 00:05:55 -0700 Subject: [PATCH 11/14] Removed Organizers file as no longer necessary --- wk4/PaulMidterm/main.rb | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/wk4/PaulMidterm/main.rb b/wk4/PaulMidterm/main.rb index 00e7c12..0784573 100644 --- a/wk4/PaulMidterm/main.rb +++ b/wk4/PaulMidterm/main.rb @@ -7,7 +7,7 @@ require_relative 'lib/gameplay' def create_player -puts "---- New Player ----" +puts "---- Player Details----" puts "Player name: " name = gets.strip puts "Player's phone number: " @@ -21,17 +21,9 @@ def create_player puts puts "*=*=*=*=*=*= Welcome to the Automatic Charade Generator! *=*=*=*=*=*=" puts -puts "What is your name?" -#grab organizer's name -organizer_name = gets.chomp -puts "What is your phone number?" -#grab organizer's phone number -organizer_phone_number = gets.to_i -organizer = Organizer.new(organizer_name, organizer_phone_number) - #Ask the organizer to choose a set of roles for the game -puts "How many players (other than you) are going to play charades?" -# TO DO: validate that input is a number +puts "How many players (including you) are going to play charades?" +# TO DO: validate that input is a number >1 participant_count = gets.to_i #Asks organizer to choose what category the game will draw from. @@ -42,6 +34,9 @@ def create_player chosen_topic = gets.to_i game=Game.new(participant_count, chosen_topic) +puts +puts "Awesome! Who's going to play charades?" +puts #Creates players and puts them into the player array 0.upto(participant_count-1) do |participant| From c15bd8a8fc9e15b3af7d5926159cef4864cd473a Mon Sep 17 00:00:00 2001 From: Paul Mumma Date: Thu, 12 Jun 2014 00:54:01 -0700 Subject: [PATCH 12/14] Got the whole thing working, including random charade assignments --- wk4/PaulMidterm/lib/gameplay.rb | 7 +++---- wk4/PaulMidterm/lib/players.rb | 7 ++++--- wk4/PaulMidterm/main.rb | 18 ++++++++++++++---- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/wk4/PaulMidterm/lib/gameplay.rb b/wk4/PaulMidterm/lib/gameplay.rb index b29c101..3757d40 100644 --- a/wk4/PaulMidterm/lib/gameplay.rb +++ b/wk4/PaulMidterm/lib/gameplay.rb @@ -1,16 +1,15 @@ class Game - attr_accessor :participant_count, :chosen_topic, :players + attr_accessor :participant_count, :players - def initialize(participant_count, chosen_topic) + def initialize(participant_count) @participant_count = participant_count - @chosen_topic = chosen_topic @players = [] end def start_playing @players.each do |player| - puts "Sending #{player.name} an SMS with their assigned role at #{player.phone_number}" + puts "Sending #{player.name} an SMS with their assigned role at #{player.phone_number}." player.send_Twilio_SMS end diff --git a/wk4/PaulMidterm/lib/players.rb b/wk4/PaulMidterm/lib/players.rb index 9eae01f..18d5237 100644 --- a/wk4/PaulMidterm/lib/players.rb +++ b/wk4/PaulMidterm/lib/players.rb @@ -3,11 +3,12 @@ require 'json' class Player - attr_accessor :name, :phone_number + attr_accessor :name, :phone_number, :assigned_charade - def initialize(name, phone_number) + def initialize(name, phone_number, assigned_charade) @name = name @phone_number = phone_number + @assigned_charade = assigned_charade end def send_Twilio_SMS @@ -22,7 +23,7 @@ def send_Twilio_SMS #FROM is from Paul's Twilio Phone number :from => '+13129975477', :to => "+1#{@phone_number}", - :body => 'Your assignment Johnny Walker', + :body => "Your charade assignment is #{assigned_charade}", }) end diff --git a/wk4/PaulMidterm/main.rb b/wk4/PaulMidterm/main.rb index 0784573..9016bd0 100644 --- a/wk4/PaulMidterm/main.rb +++ b/wk4/PaulMidterm/main.rb @@ -3,9 +3,10 @@ #Welcome the game organizer require_relative 'lib/players' -require_relative 'lib/organizer' require_relative 'lib/gameplay' + + def create_player puts "---- Player Details----" puts "Player name: " @@ -13,8 +14,17 @@ def create_player puts "Player's phone number: " # HAVE TO FIND A WAY TO CHECK AND CLEAN INPUT phone_number=gets.strip +#Assigns player to a value from the selected topic array +charade_arrays=[ + ["Augustus","Cleopatra","Dionysius","Hannibal","Lucretius", "Maecenas", "Plato", "Romulus", "Sappho", "Virgil"], + ["Alice in Wonderland", "Harriet the Spy", "James and the Giant Peach", "Frog and/or Toad", "Runaway Bunny", "Harry Potter", "Johnny Tremain", + "Snow White", "Paul Atreides", "One of the Norwegians in Snow Treasure"], + ["Mark Zuckerberg", "Cheryl Sandberg", "Jerry Yang", "Aaron Levie", "John Doerr", "Joi Ito", "Sergey Brin", "Travis Kalanick", "Marissa Meyer", + "Dr. Dre"] +] +assigned_charade=charade_arrays[@chosen_topic-1][rand(0..9)] -Player.new(name,phone_number) +Player.new(name,phone_number, assigned_charade) end @@ -31,9 +41,9 @@ def create_player puts "Which category do you want to draw from? Enter a number to choose one of the following:" puts puts "(1) Famous Greeks and Romans \n(2) Children's Book Characters \n(3) Silicon Valley Who's-Who" -chosen_topic = gets.to_i +@chosen_topic = gets.to_i -game=Game.new(participant_count, chosen_topic) +game=Game.new(participant_count) puts puts "Awesome! Who's going to play charades?" puts From 9004a263c33da28d90251fb043592cb52f2b6e3f Mon Sep 17 00:00:00 2001 From: Paul Mumma Date: Thu, 12 Jun 2014 15:00:09 -0700 Subject: [PATCH 13/14] Files for midterm submission --- wk4/PaulMidterm/main.rb | 47 +++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/wk4/PaulMidterm/main.rb b/wk4/PaulMidterm/main.rb index 9016bd0..7cb0272 100644 --- a/wk4/PaulMidterm/main.rb +++ b/wk4/PaulMidterm/main.rb @@ -11,10 +11,15 @@ def create_player puts "---- Player Details----" puts "Player name: " name = gets.strip -puts "Player's phone number: " -# HAVE TO FIND A WAY TO CHECK AND CLEAN INPUT +puts "Player's phone number (no dashes, please!): " +# Grab user phone number, use (ugly!) loop to guard against invalid phone numbers phone_number=gets.strip -#Assigns player to a value from the selected topic array +until phone_number.length == 10 + puts "Please enter a valid phone number (including area code, excluding country code, no dashes)" + phone_number = gets.strip +end + +#Assigns player to a random charade from the topic array chosen by the organizer charade_arrays=[ ["Augustus","Cleopatra","Dionysius","Hannibal","Lucretius", "Maecenas", "Plato", "Romulus", "Sappho", "Virgil"], ["Alice in Wonderland", "Harriet the Spy", "James and the Giant Peach", "Frog and/or Toad", "Runaway Bunny", "Harry Potter", "Johnny Tremain", @@ -24,6 +29,7 @@ def create_player ] assigned_charade=charade_arrays[@chosen_topic-1][rand(0..9)] +#Create the player Player.new(name,phone_number, assigned_charade) end @@ -31,14 +37,26 @@ def create_player puts puts "*=*=*=*=*=*= Welcome to the Automatic Charade Generator! *=*=*=*=*=*=" puts +puts "The idea is simple: rather than use pesky pieces of paper, let a computer assign charades to each player.\nThat way, no cheating!\nAnd since APIs are cool, we'll send each player their assignment using the Twilio SMS API. \nThink of it as a parlor game for the 21st century." +puts +puts "OK - let's get started!" #Ask the organizer to choose a set of roles for the game puts "How many players (including you) are going to play charades?" -# TO DO: validate that input is a number >1 +puts "Player count: " +# Asks the organizer for the player count. Uses until loop to make sure total is greater than 1 and less than 11 (since there are only 10 choices in each assignment array) participant_count = gets.to_i - +until participant_count > 1 && participant_count < 11 + if participant_count < 2 + puts "Please enter a value greater than 1! (You can't play charades with yourself!)" + elsif participant_count > 10 + puts "Please enter a value no greater than 10! (There are only so many charades to be assigned!)" + end + participant_count = gets.to_i +end +puts #Asks organizer to choose what category the game will draw from. #TO DO: allow organizer to create his own category OR combine existing categories -puts "Which category do you want to draw from? Enter a number to choose one of the following:" +puts "Which category do you want to draw the charade assignments from? \nEnter a number to choose one of the following:" puts puts "(1) Famous Greeks and Romans \n(2) Children's Book Characters \n(3) Silicon Valley Who's-Who" @chosen_topic = gets.to_i @@ -55,19 +73,12 @@ def create_player puts "#{player.name} added successfully" end -while 1==1 -puts "Ready to Play? (y/n)" +puts "Ready to Play? Type 'y' when ready." answer = gets.chomp.downcase -if answer=="y" - puts +until answer == "y" + puts "Please type 'y' when you're ready to play." + answer = gets.chomp.downcase +end game.start_playing puts puts "All messages sent - now go play charades!" - exit -elsif answer == "n" - puts "No problem - just exit the program and start over" - exit -else - puts "Please enter a valid answer ('y' or 'n')" -end -end From 840d8fbff99461d912da0f756bbd4dd42f8a4b49 Mon Sep 17 00:00:00 2001 From: Paul Mumma Date: Thu, 12 Jun 2014 18:14:27 -0700 Subject: [PATCH 14/14] adding everything --- wk4/midterm.rb | 22 ++++++++++++++++++++++ wk4/organizer.rb | 10 ++++++++++ wk4/players.rb | 8 ++++++++ wk4/readme.txt | 22 ++++++++++++++++++++++ wk4/thursday.rb/thursday.rb | 0 wk4/topics.rb | 0 6 files changed, 62 insertions(+) create mode 100644 wk4/midterm.rb create mode 100644 wk4/organizer.rb create mode 100644 wk4/players.rb create mode 100644 wk4/readme.txt create mode 100644 wk4/thursday.rb/thursday.rb create mode 100644 wk4/topics.rb diff --git a/wk4/midterm.rb b/wk4/midterm.rb new file mode 100644 index 0000000..dcfd680 --- /dev/null +++ b/wk4/midterm.rb @@ -0,0 +1,22 @@ + + + +# The API Part! - Twilio SMS send + +require 'rubygems' # not necessary with ruby 1.9 but included for completeness +require 'twilio-ruby' +require 'json' +require 'pry' + +# put your own credentials here +account_sid = 'AC277cf35a20573e1d13f3c50f45b92612' +auth_token = '0379092183f9ef2732e7a08f82bb50fe' + +# set up a client to talk to the Twilio REST API +@client = Twilio::REST::Client.new account_sid, auth_token + +@client.account.messages.create({ + :from => '+13129975477', + :to => '+19083471778', + :body => 'Assigned role: Johnny Walker', +}) \ No newline at end of file diff --git a/wk4/organizer.rb b/wk4/organizer.rb new file mode 100644 index 0000000..e7d9b1f --- /dev/null +++ b/wk4/organizer.rb @@ -0,0 +1,10 @@ +# class Organizer + +# attr_accessor :name, :organizer_phone_number + +# def initialize(name, organizer_phone_number) +# @name = name +# @organizer_phone_number = organizer_phone_number +# end + +# end diff --git a/wk4/players.rb b/wk4/players.rb new file mode 100644 index 0000000..bf304bb --- /dev/null +++ b/wk4/players.rb @@ -0,0 +1,8 @@ +class Player + attr_accessor :name, :phone_number + + def initialize(name, phone_number) + @name = name + @phone_number = phone_number + end +end diff --git a/wk4/readme.txt b/wk4/readme.txt new file mode 100644 index 0000000..545095f --- /dev/null +++ b/wk4/readme.txt @@ -0,0 +1,22 @@ +Paul's awesome SMS charade game Readme + +Created: June 12, 2014 +Last updated: June 12, 2014 + + +Premise of the game: + - In a typical game of charades, the organizer has to (a) choose the options for each player, and (b) find a way to distribute the assignments (usually on pieces of paper) + - My game solves both problems: the program will randomly assign a charade to each player, and sends the assignment via SMS + - As an added bonus, the game includes a number of pre-populated categories of charades, so the organizer simply chooses a category, and the system does the rest. This means that the organizer doesn't know everyone else's charade! + +Known issues: + - The biggest known issue is that the random assignment of charades to each player does not protect against duplicate assignments. I didn't have time to figure that one out. So players may have the same assignment... + +Desired enhancements: + - In addition to solving the possibility for overlapping assignments (above), my other goal was to allow the organizer to create a new category of charade assignments, and populate this array with their own choices. This wouldn't be too hard, but again, I ran out of time! + +Notes for BEWD grading team: + - In terms of the API integration, I decided to use the Twilio SMS API library. Super easy, and pretty functional + - Note that you do need to input a REAL phone number to get the real effect of the game. I have intentionally allowed you to assign the same phone number to multiple users, so that you can test the game without using multiple phone humbers. You'll just get >1 text + - Other than the obvious issues above, I think there is some spaghetti organization going on here. Specifically, I think "main" includes more game logic than I would have liked. + - I'd love macro feedback on how the game might be organized better going forward diff --git a/wk4/thursday.rb/thursday.rb b/wk4/thursday.rb/thursday.rb new file mode 100644 index 0000000..e69de29 diff --git a/wk4/topics.rb b/wk4/topics.rb new file mode 100644 index 0000000..e69de29