Code Monkey home page Code Monkey logo

cookbook_sinatra's Introduction

Background and Objectives

Terminal apps are cool, but you know what's cooler? Web applications! Let's try to port our Cookbook to a new web application using the sinatra gem.

Some words about Sinatra

Sinatra is what we call a web "microframework". It's basically a micro Rails, also following the MVC pattern. The app.rb file acts as the controller. The router layer is handled by Sinatra. We already created a controller method to handle the root of the web app. Sinatra maps the URL in the browser to the right method in app.rb. Take a look at the routing doc for more info.

Read more about Sinatra in our homemade tutorial. Follow the setup, sinatra app and views steps thoroughly before starting your Cookbook web app.

Specs

In our web app, we'll use our Recipe and Cookbook classes as we left them earlier. We won't need the Router and Controller classes though.

Index

At the root of your web app (at the / url), you should display your cookbook's recipes in an unordered list.

Under the list of recipes, add a navigation link (<a>) to the /new url, that we'll use for the create user story.

Create

Creating a new recipe takes two steps in the context of our web app. We need one step to display a form. We'll use a GET /new HTTP request to display the form.

The <form> will be the equivalent of the gets in the terminal. We need fields for the recipe's name, description, and any other field you find relevant to add. Submitting this form should trigger the following HTTP request:

POST /recipes

This request should trigger some code in app.rb to add the recipe in the cookbook. At the end of this code, find a way to redirect the user to the / url of your web app (the index).

Destroy

In your index, add a destroy link next to the name and the description of the recipe. Clicking on the link should remove it from the cookbook and redirect to the index.

Going further

When you managed to code these 3 user stories, go on and try to implement the harder import and mark as done actions!

Happy Sinatra!

cookbook_sinatra's People

Contributors

steppan26 avatar

Stargazers

 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.