Git Product home page Git Product logo

01-stupid-coaching's Introduction

Background & Objectives

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.

Specs

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

Generate a CoachingController

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

Your coach answer logic

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

Coach answer to question

Coach answer to assertion

Ask a question using a form

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 form
  • name 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.

Coach answer to assertion

Add a backlink in answer.html.erb

  • Add a link to /ask on the answer.html.erb view using the link_to Rails helper.

Coach answer to assertion

01-stupid-coaching's People

Contributors

emmasdn avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.