Last active
December 16, 2015 02:59
-
-
Save Shiggiddie/643e7153605354b84686 to your computer and use it in GitHub Desktop.
Ruby/Rails HW: get/post routes, passing parameters into .erb templates, .erb if/else template logic
This file contains 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
# 1) Make necessary modifications to a rails project such that an HTML response of "<h1>Hello World</h1>" | |
# is returned when hitting the path "/hello_world/index" with a GET request | |
# 2) Devise a shell utility "curl" command that makes a GET request of the path constructed in #1 | |
# 3) Make necessary modifications to the rails project such that an HTML response of "<h1>Hello POST world</h1>" | |
# is returned when hitting the path "/hello_world/index" with a POST request, do not remove any code created in #1 | |
# 4) Devise a shell utility "curl" command that makes a POST request of the path constructed in #2 | |
# 5) Make necessary modifications to the rails project such that an HTML response of "<h1>Hello POST world PLUS</h1>" | |
# is returned when hitting the path "hello_world/index" with a POST request AND a payload that contains the key/value pair | |
# "plus"/"true", otherwise the HTML response should be "<h1>Hello POST world NO-PLUS</h1>" | |
# 6) Devise two shell utility "curl" commands that invoke the two different responses described in #5 | |
# 7) Make necessary modifications to the rails project such that the POST request from #5 is able to handle requests | |
# for both HTML and JSON renderings. For the HTML rendering, handle exactly the same as #5. For the JSON rendering, | |
# respond with a JSON object that contains the key/value pair "plus"/<"true" or "false", depending on the value of the | |
# payload "plus" value. | |
# 8) Devise two more shell utility "curl" commands tha tinvoke the two different JSON responses described in #7, also use | |
# the two shell utility "curl" commands devised in #6 to prove that they still work |
- curl -X POST "http://localhost:3000/hello/index" -d ""
Hello POST World
Reni:pause_pray_2 (dick) [2.1.1]$- curl -X POST "http://localhost:3000/hello/index" -d "plus=hjdgadjhgf"
Hello POST world PLUS
Reni:pause_pray_2 (dick) [2.1.1]$ curl -X POST "http://localhost:3000/hello/index" -d "plus="Hello POST world PLUS
Reni:pause_pray_2 (dick) [2.1.1]$ curl -X POST "http://localhost:3000/hello/index" -d ""
Hello POST world NO-PLUS
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Generated a rails controller called Hello World. Hello is the name of the controller and World is the action. Looking at the documentation, rails plays well with CamelCase naming, so if we wanted to tweak it to better match the question, I could have done this command instead: "rails generate controller HelloWorld Index". This stack overflow question helps answer the issue I was seeing with underscores: http://stackoverflow.com/questions/3154272/rails-would-like-to-create-a-controller-with-a-dash-or-underscore-in-name
curl -X GET http://localhost:3000/hello/world