Giter Club home page Giter Club logo

cookie-monster-app's Introduction

Cookie Monster App

In this lab we will explore cookies and sessions in rails. First we'll play with manually setting cookies on the front-end. Then we'll explore how cookies are used to create "sessions" that keep track of user data on the server-side.

Setup

Clone this repo, bundle, and run the server.

cd cookie_monster_app
bundle
rails s

Note: This rails application does not use a database or turbolinks.

Challenges

To begin, visit http://localhost:3000/desserts in your browser, with the Chrome Console open.

  1. Use the Chrome Console to manually set a cookie for the website to: fav_color=blue. When you refresh the page, a script running on the page will detect the color and apply it to the background of the page.
  2. Manually add a second cookie (can_access=yes) so that you can access the 3 desserts#show pages (/desserts/1, /desserts/2, /desserts/3).
  • The server is actually checking for this cookie in the HTTP Request Headers (see the desserts#show controller). Without this cookie, you will be blocked (redirected) from viewing all dessert pages!
  1. When a user clicks "Save as Favorite" on a desserts#show page, store the dessert id in the user's session. (See app/controllers/desserts_controller.rb)
  2. Modify the desserts#show view to indicate whether the dessert shown is the user's favorite dessert (See app/controllers/desserts_controller.rb and app/views/desserts/show.html.erb).
  • How would you compare the current_dessert to the user's favorite dessert? Can you use this comparison to create a "conditional view"?
  1. Stretch: Can you DRY up the controller code by using a before_action to check whether the user is logged in?

Pay special attention to Resources > Cookies > localhost in the Developer Console. The Cookies-view allows you to browse and delete cookies associated with the current domain.

Take Away

What's the difference between a cookie and a session?

By the end of this lab you should be able to explain how and why these cookies are present in your browser:

screen shot 2016-01-11 at 7 30 58 pm

Resources

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.