Skip to content

Instantly share code, notes, and snippets.

@Shiggiddie
Last active December 16, 2015 02:59
Show Gist options
  • Save Shiggiddie/643e7153605354b84686 to your computer and use it in GitHub Desktop.
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
# 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
@rgsoto
Copy link

rgsoto commented Apr 4, 2015

  1. 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

  2. curl -X GET http://localhost:3000/hello/world

<!DOCTYPE html>
<html>
<head>
  <title>PausePray2</title>
  <link data-turbolinks-track="true" href="/assets/hello.css?body=1" media="all" rel="stylesheet" />
<link data-turbolinks-track="true" href="/assets/prayers.css?body=1" media="all" rel="stylesheet" />
<link data-turbolinks-track="true" href="/assets/scaffolds.css?body=1" media="all" rel="stylesheet" />
<link data-turbolinks-track="true" href="/assets/welcome.css?body=1" media="all" rel="stylesheet" />
<link data-turbolinks-track="true" href="/assets/application.css?body=1" media="all" rel="stylesheet" />
  <script data-turbolinks-track="true" src="/assets/jquery.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery_ujs.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/turbolinks.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/hello.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/prayers.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/welcome.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/application.js?body=1"></script>
  <meta content="authenticity_token" name="csrf-param" />
<meta content="3ePWbEgI54R5GtjvXy4iVY9J0apDZYE6TYhIttIc+pE=" name="csrf-token" />
</head>
<body>

<p> Hello World </p>


</body>
</html>

@rgsoto
Copy link

rgsoto commented Apr 30, 2015

  1. curl -X POST "http://localhost:3000/hello/index" -d ""

Hello POST World

Reni:pause_pray_2 (dick) [2.1.1]$

@rgsoto
Copy link

rgsoto commented Apr 30, 2015

  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