Giter VIP home page Giter VIP logo

week3-homework's Introduction

Week 3 Homework

(5 points)

FORK this repository before you start.

DUE: You must push your code to GitHub no later than Tuesday, July 14 at 5:29PM.

Overview

Your job is to transform this app into a database-backed web application.

1 point per challenge, plus up 1 point for code readability (good variable names, consistent indentation, etc.) for a total of 5 points.

Challange #1: A Place Model

By the end of this challenge, you should have 2 routes like this:

  root 'places#index'
  get '/places' => 'places#index'
  1. Create a model named Place that can keep track of each place's title, photo url, admission price, and description. The title can be limited to 255 characters, but the description shoud support text at least 1000 characters in length. The admission price should be stored as integer representing the number of cents.
  2. Write code in your db/seeds.rb file so that it is prefills the database with at least 5 places. Make sure that you can run the seeds file multiple times and still end up with the same number of places each time.
  3. Implement an index action that is database-driven and displays the list of places using <ul> and <li> elements.

Challenge #2: Let Users View Details

By the end of this challenge, you should have 3 routes like this, but not necessarily in this order:

  root 'places#index'
  get '/places' => 'places#index'
  get '/places/:id' => 'places#show'
  1. Support the following url: /places/:id and connect it to an action method named show in the PlacesController. This action should display all of the details of a particular Place.
  2. Modify the index action so that clicking on a place links to the show page for that place.

Challenge #3: Delete Places

By the end of this challenge, you should have 4 routes like this, but not necessarily in this order:

  root 'places#index'
  get '/places' => 'places#index'
  get '/places/:id' => 'places#show'
  get '/places/:id/delete' => 'places#delete'
  1. On the index page, add a link next to each place that will trigger the places#delete action.
  2. When the user clicks the link, that Place should be removed from the database, and the user should be redirected back to the index page to verify that the place has been removed.

Challenge #4: Add and Edit Places

By the end of this challenge, you should have these 8 routes, but not necessarily in this order:

  root 'places#index'
  get '/places' => 'places#index'
  get '/places/:id' => 'places#show'
  get '/places/:id/delete' => 'places#delete'
  get '/places/new' => 'places#new'
  get '/places/submit_new' => 'places#create'
  get '/places/:id/edit' => 'places#edit'
  get '/places/:id/update' => 'places#update'
  1. At the top of the index page, add a link to add a new place. The link should navigate to /places/new, which must display a form for the user to fill in (title, url, price, and a description).
  2. The form should target the create action. When the user submits the form, a new row should be added to the database, and the user should be redirected back to the index action to see a refreshed list that now includes their new place.
  3. On the show page, add a link to /places/:id/edit which should display a form to edit the details of the place.
  4. The edit form should be prefilled with data from the database, and it should trigger the update action when the suer clicks Submit.
  5. The update action should update the row in the database, and redirect to /places/:id so the user can verify that the database has been updated.

HINTS

Research the value attribute of HTML input elements to learn how to prefill default values into input fields.

If something isn't working and you can't figure out why, watch the server log.

Here are some Rails view helper methods that you might find helpful:

FRIENDLY WARNING: Contrary to what you may read online, do NOT use form_tag or form_for (at least, not this week).

And here are some command-line utilities that are helpful:

  • rake db:migrate
  • rake db:seed

week3-homework's People

Contributors

coreywhiting avatar jeffcohen avatar

Watchers

James Cloos 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.