config.generators do |g| g.test_framework :rspec, fixtures: true,
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def factorial(num) | |
| if num <= 1 | |
| 1 | |
| else | |
| num * factorial(num-1) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # require 'Rack' | |
| # class YourAppClass | |
| # def call(env) | |
| # [200, {'Content-Type' => 'text/html'}, ['Hello Rack!']] | |
| # end | |
| # end | |
| # run YourAppClass.new |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| does it change the database? | |
| where am I going to store that data? | |
| what data needs to be stored? | |
| name | |
| the songs on the mixtape | |
| - write my migration | |
| how does that effect my models? | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # GREED GAME | |
| def score(dice) | |
| return 0 if dice == nil | |
| score = 0 | |
| counts = [0,0,0,0,0,0] | |
| dice.each { |roll| counts[roll-1] += 1 if (1..6) === roll } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| source 'https://rubygems.org' | |
| # Frameworks | |
| gem 'rails', '4.0.2' | |
| # Server | |
| gem 'unicorn' | |
| # Database | |
| gem 'pg' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'nokogiri' | |
| require 'open-uri' | |
| require 'pry' | |
| class Scraper | |
| def initialize | |
| @student_data = [] | |
| @index_url = "http://students.flatironschool.com/" | |
| @index = Nokogiri::HTML(open(@index_url)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| =Navigating= | |
| visit('/projects') | |
| visit(post_comments_path(post)) | |
| =Clicking links and buttons= | |
| click_link('id-of-link') | |
| click_link('Link Text') | |
| click_button('Save') | |
| click('Link Text') # Click either a link or a button | |
| click('Button Value') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Kickstarter Project Scrape | |
| require 'nokogiri' | |
| # HTML, XML parser that allows us to view HTML code as series of nodes; able to highlight elements via CSS selectors | |
| require 'open-uri' | |
| # Module that allows you to make http request, and returns us the HTML content of a URL via the `open` command | |
| require 'pry' | |
| # projects | |
| # kickstarter.css("li.project.grid_4") |
- Most magical form helper in rails
- form_for is a ruby method into which a ruby object is passed
- form_for yields a form builder object (typically
f) - methods to create form controls are called on
f, the form builder element - when the object is passed as a form_for parameter, it creates corresponding inputs with each of the attributes
- if i had
form_for(@cat), then the form field params would look likecat[name],cat[color], etc
- if i had
- in keeping with Rails convention regarding RESTful routes, there should be a resource declared for each model object (eg,
resources :cats)