A Sinatra Project — TrendsInTheNews

Spotswood
3 min readMar 8, 2021

A personalized archive of news articles to help identify trends in the news.

For my second Flatiron project, my application had to meet the following requirements:

  • Be a MVC Sinatra web application
  • Use ActiveRecord
  • Use Create, Read, Update, and Destroy (CRUD) actions
  • Create Valid User Accounts

The idea

It’s my job to check the news every day in order to stay up to date on trends, but I always have to search around to find what I’m looking for. I thought it would be nice to have a centralized place where I can view news articles, leave comments on those articles, and save them to an archive I can refer back to. Having a personalized list of news trends is useful in marketing.

Creating the idea

The news is crazy these days, and news sources are biased. I wanted to pick and choose my news instead of being fed articles news sources think are important to me. Rather than search for a product, I took on the challenge of creating an application with simple features I would actually use. This is TrendsInTheNews.

I made use of the base Sinatra application for this project, building views that allow the user to signup, login, see news articles, leave comments on those new articles, and find their comments in an archive. Inside the archive, users can edit or delete previous comments. By using ActiveRecord associations and SQLite in my application, I built routes that handle user creation and validation then save inputs in a local database. When a user signs up or logs in, the application checks for email uniqueness and validity. I used the bcrypt ruby gem to provide security for my application, encrypting user passwords within the sqlite3 database. The Sinatra Flash gem allowed me to add error notifications to routes, which display when a user tries to persist bad data to the database. Users have the ability to create and save many comments associated with an article within the web application, making use of various views and routes.

Technical problem I faced

Creating comments in an application is useful, but it wouldn’t make much sense if the application only showed comments. You want your comments connected to an article right? The solution was nested routes.

When a user is signed in and navigates to their archive, they are able to see their comments by clicking on an article. Articles have many comments and the comments belong to an article. Inside my comments controller, I created nested routes that contain an articles’s id number. This allowed my application to get only the comments associated to that article, not all of the users comments. Here is an example of a nested route that navigates to a show page displaying a specific comment on a specific article:

get '/articles/:article_id/comments/:id' doget_articleget_commenterb :'comments/show'end

Conclusion

Although the application is not fully complete (still need to test the idea), I’m excited about what the project has become. This phase of the Flatiron curriculum pushed me to think more conceptually and plan well, building an idea from nothing. Becoming a developer is a difficult process, but projects like this restore my faith in learning the skill. I’ve built the foundation for thinking like a developer in four short months, and the learning curve continues to improve.

--

--

Spotswood

I write about software development projects in JavaScript (React), Ruby on Rails, R, and other languages 🧱🏗👷🏻‍♂️