The goal of the next two challenges is to re-implement some of your ruby scripts in Rails. That means:
- Your program interface isn't the terminal anymore, it is your browser now.
- The only way to communicate with your Rails app is through HTTP requests.
Re-implement the stupid coaching challenge (01-Ruby/01-Programming-basics/05-Stupid-coaching) in Rails.
Get familiar with Rails command line basics. For this exercise, you should know at least how to:
- create a new Rails app
- launch a web server to test your app locally
- generate a new controller from the command line
- check your routes with the relevant
rake
task
Once you have created your new coaching app, add a new CoachingController
, using the adequate rails generator on the command line. This controller will have two actions, CoachingController#answer
and CoachingController#ask
Implement a first route GET '/answer'
to your CoachingController#answer
action. The answer.html.erb
will display the question you ask your coach as well as his answer.
Your question to your coach should be given as a parameter named :query
. Ex: GET /answer?query=hello
or GET /answer?query=what+should+i+do?
.
Implement a new route GET '/ask'
to your CoachingController#ask
action. This action is here to build the page including your HTML form. Here is the code for the form.
<form action="/???">
<label for="question">Speak to your coach</label>
<input type="text" id="question" name="???" placeholder="what time is it?">
<input type="submit" value="Go on!">
</form>
Notice the important HTML attributes in the form:
action
specifies the URL that will be used when submitting the formname
enables you to name each parameter corresponding to each input of the form.
Replace the ???
so that your form send a request to CoachingController#answer
with a good parameter name.
- Add a link to
/ask
on theanswer.html.erb
view using thelink_to
Rails helper.