Project for Week 2

Review

Topics Covered: Databases, Active Record, Schema, Migrations, Seeds

Project: Lekker Plekke

Rails App

You will have 2 days to complete this project. We recommend starting tonight. Our cool places app, Lekker Plekke, will allow us to keep track of and share all of the cool places we find in Cape Town. Create a new rails app called lekker_plekke inside of your ixperience folder, and initialize a git repository.

Place Model

  1. Generate a Place model. What attributes do you think your Place model will need? Try to think of at least two useful attributes (hint: name might be useful!).
  2. Use seeds.rb (or the rails console) to seed your database with a few cool places in Cape Town that you've seen so far!

Places Controller & Routes

  1. Create a places controller, with a CRUD functionality
  2. Create appropriate views for CRUD actions.
    • On the index page, list all places by name.
    • On the show page, display an individual place, including all attributes.
    • On the new page, display a form to create a new place.
    • On the edit page, display a form with existing features filled so a user can update the place.
    • Add appropriate links to navigate between the views.
    • Add a destroy link to each place listed on the index page.
  3. Create corresponding routes for all of your views/actions

Challenge (Optional)

Although this is optional, we recommend that you try to complete as much of the challenge as you can.

  1. Create a Comment model and a comments controller. Each comment needs to have the name of the person posting (commenter), the text of the comment (text), as well as a reference to the place.
  2. Add an association between Comment and Place. A Place has_many :comments and a Comment belongs_to :place. Make sure your schema reflects this association as well.
  3. Add a form on the place show page that will allow the user to create a new comment. Also display all comments associated with a particular place on the place show page.
  4. Add functionality to "like" a certain place or a certain comment. To do so, add an attribute called likes which is an integer to your desired model. Add a link, route, and controller method that will increment the number of likes when the link is clicked on.

Bonus (Optional)

Let's add some styling. An easy way of making your web apps look instantly better is to use Bootstrap. Bootstrap provides you with custom CSS, Javascript, and some other fun things that you can use once installed into your app. For example, Bootstrap pre-defines CSS classes to make your HTML elements look a certain way. To make your site match, you can just add the same CSS class to your HTML. To read more, you can check out this resource.

For our purposes, we just need to install the css into our rails app. To install:

  1. Go to your Gemfile
  2. Add gem "twitter-bootstrap-rails" to the list.
  3. Run bundle install.
  4. Run rails generate bootstrap:install static

Some background on gems: you can view gems as libraries or plug-ins specifically made for rails apps. It's some functionality (ie styling, passwords) that you install to fill a specific need. Gems are super powerful, and you should definitely use them in your final project!

Voila! Play around with adding certain CSS classes to your HTML elements! You can refer to the css page of Bootstrap for reference.

Example Lekker Plekke

P.S. This includes the bonus and extra bonus! If your app doesn't look exactly like this, don't panic. As long as the content for the index and the show pages are there, you're all set.

Great work! Now add and commit your work then push it to GitHub :)