Read these instructions carefully. Understand exactly what is expected before starting this Sprint Challenge.
This is an individual assessment. All work must be your own. Your challenge score will be a measure of your ability to work independently using the material covered during this sprint. You need to demonstrate proficiency in the concepts and objectives introduced and practiced in the preceding days.
You are not allowed to collaborate during the Sprint Challenge. However, you are encouraged to follow the twenty-minute rule and seek support from your PM and Instructor in your cohort help channel on Slack. Your work reflects your proficiency in Ruby and Ruby on Rails Basics.
You have three hours to complete this challenge. Plan your time accordingly.
Commit your code regularly and meaningfully. This helps both you (in case you ever need to return to old code for any reason) and your project manager.
You are going to create a rails application called awesome_blog
. Your job is to set up the blog so that it contains posts
and quotes
which are similar but quotes
do not contain a title
field.
- Fork the project into your GitHub user account
- Clone the forked project into a directory on your machine
- Create a pull request before you start working on the project requirements. You will continuously push your updates throughout the project.
- You are now ready to build this project with your preferred IDE
When your project is completed, you will be able to run a rails development server in order to create posts and quotes on the front-end. This data will be persisted to a database.
You will have a WordCounter module that will be included in your Post
and Quote
models so that you can get the number of words on any of your posts
or quotes
.
You will also create a AppStats
class with numerous methods that you can use from the rails console to get statistics about your application's posts
and quotes
.
These are the steps you should take in order to create your MVP:
- Create a new rails application called
awesome_blog
. - Scaffold a posts resource that has the following attributes:
- title:string
- body:text
- published_at:datetime
- Scaffold a quotes resource that has the following attributes:
- body:text
- published_at:datetime
- Run the migration command to update the database with the new resources.
- Run the rails server and use the appropriate url endpoints to add some
posts
andquotes
to your application - Create a single Module called WordCounter in the
app/models
folder. - Write a method in the module named
word_count
that counts the total number of words in thebody
attribute of any file it is mixed into. If the body isnil
, you should return0
. - The
Quote
andPost
model files shouldeinclude
theWordCounter
module. - Create a class called
AppStats
in theapp/models
directory. Create two instance variables--one forposts
and one forquotes
. Make sure to set them up with theattr_reader
method so they can be accessed externally but not changed externally. Use theinitialize
method to store all the posts in the posts instance variable and all the quotes in the quotes instance variable. - Create the following methods in the
AppStats
class:posts_count
: returns the number of postsquotes_count
: returns the number of quotesposts_word_count
: returns the word count of all posts in one sumquotes_word_count
: returns the word count of all quotes in one sumtotal_count
: returs the total of all posts and quotes in one sumtotal_word_count
: returns the total of all words in posts and quotes in one sum
- Utilize the rails console to instantiate the
AppStats
class and use it to test all of the statistical methods you created.
- Create a controller and views to show
AppStats
data on the root route.