[ Launch: reddit base ] 4753337abc6bcef1ff6f2d8677250073 by ericbooker12[ Launch: reddit base ] 6633418 by enjalot[ Launch: simple histogram ] 6631652 by enjalot
  
    
      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
    
  
  
    
  | license: mit | 
  
    
      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
    
  
  
    
  | license: gpl-3.0 | 
  
    
      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
    
  
  
    
  | license: gpl-3.0 | 
  
    
      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
    
  
  
    
  | license: mit | 
  
    
      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
    
  
  
    
  | license: mit | 
HTML and Sinatra really only support the GET and the POST methods. In order to be able to use the PUT and DELETE methods in Sinatra, you kind of have to "trick" the form to go to the right place. Then you can name the routes the proper way - otherwise you can only really work with GET and POST.
I used the Craiglist Jr challenge for some examples. Let's look at a quick example of a POST form/method/route- in this case, we're creating a new Craigslist article:
POST form and corresponding route:
<form action="/article/new" method="post">
  --------------------------------
  YOUR FORM FIELDS HERE
  
    
      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
    
  
  
    
  | Add helpers here as *.rb files, e.g., | |
| app/helpers/formatting.rb | |
| helpers do | |
| def em(text) | |
| "<em>#{text}</em>" | |
| 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
    
  
  
    
  | class Hospital | |
| attr_reader :patients, :name | |
| def initialize(name, patients = []) | |
| @name = name | |
| @patients = patients | |
| end | |
| def find_patient_by_name(name) | |
| patients.find { |patient| patient.name == name } |