FORK this repository before you start.
DUE: You must push your code to GitHub no later than Thursday, April 23 at 5:29PM.
Your job is to transform the Chicago app into a database-backed web application.
You can earn up to 2 points per challenge, plus up to 2 points for code readability (good variable names, consistent indentation, etc.) for a total of 10 points. Points are awarded for correctness and
- 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.
- Rewrite the
index
action so that is database-driven. There should be no hardcoded data in any of your code by the time you are done. - 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.
By the end of this challenge, you should end up with 3 routes like this:
get '/places' => 'places#index'
get '/places/:id' => 'places#show'
get '/places/:id/delete' => 'places#delete'
- Support the following url:
/places/:id
and connect it to an action method namedshow
in thePlacesController
. This action should display all of the details of a particular Place. - Modify the
index
action so that each place links to theshow
page for that place. - On the
index
page, also add a link to/places/:id/delete
such that when the user clicks the link, that Place should be removed from the database, and the user should be redirected back to theindex
page to verify that the Place has been deleted.
By the end of this challenge, you should have these 7 routes:
get '/places' => 'places#index'
get '/places/:id' => 'places#show'
get '/places/:id/delete' => 'places#delete'
get '/places/:id/new' => 'places#new'
get '/places/:id/create' => 'places#create'
get '/places/:id/edit' => 'places#edit'
get '/places/:id/update' => 'places#update'
- 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). The form should target thecreate
action. When the user submits the form, a new row should be added to the database, and the user should be redirected back to theindex
action to see a refreshed list that now includes their new place. - On the
show
page, add a link to/places/:id/edit
to display a form for the user to edit the details of the place. The form should target theupdate
action, which should update the row in the database, and redirect to/places/:id
so the user can verify that the database has been updated.
You are free to invent the URLs, routes, controller(s) (if any) and actions necessary to achieve the following:
- Create a
Review
model that connects a Place to zero or more reviews. A review should have a short title, a rating from 0 to 5, and a long description. - On the
show
page for a place, add a form so that users can submit a review. When a review is submitted, the user should see their review inserted at the top of the list of reviews. - Any existing reviews should appear below the form.
Here are some Rails view helper methods that you might find helpful:
And here are some command-line utilities:
rake db:migrate
rake db:seed
If something isn't working and you can't figure out why, watch the server log.
Warning: contrary to what you may read online, do not use form_tag
or form_for
(at least, not this week).