DEV Community

alliecaton
alliecaton

Posted on

Book Tracking Rails App

This app is available for use at: https://shelvd-app.herokuapp.com/

For my rails application, I built a very simple version of a book tracking app like Goodreads or The Storygraph. I love to read, so I wanted to make something that I could actually use myself! I've been feeling demystified with Goodreads recently, so wanted to make something that suited my most baseline needs for a book tracking app.
homepage of Shelvd

My rails application has definitely been the most challenging project yet, but I've also learned the most during this process. The biggest thing I think I took away from this, aside from new hard programming skills, is the importance of project preparation. For our last two projects, we had a one week buffer off the back of our week-long project week. For both of those projects I filled that extra week to the brim expanding my application, changing things, and iterating. This time around, there was no time to iterate or change beyond the most essential refactoring. I didn't fully think through how having one week less to work on this project would affect the experience of it, so I planned about as much as I had with my CLI and Sinatra project(which, to say the least, was not sufficient for building something with such a tight scope). I've definitely come to understand the importance of structure and well thought out plans when tasked with a tight timeframe during this experience.

Anyway, let's get into the app!

My application has eight main models (two of which are purely join tables with no other function)

  • Author
  • Book
  • BooksAuthor
  • BooksShelf
  • Post
  • ReadingRoom
  • Shelf
  • User

For gathering book information, I used the GoogleBooks gem. It packages up the Google Books API into an easy to use gem.

The interactions between Users and Shelves is pretty straight forward-- shelves are lists the User can create to track books with. The books have authors, a description, and average rating information attached to them. In the future, I'd like to expand my application to allow users within my app to add a rating/review to books they've read.

The other side of my application is the ReadingRoom model. I didn't have enough time to flesh out a Friend-to-Friend structure (I would like to add this in the future), but I still wanted to include a bit of a social aspect to the application. Reading Rooms are like mini forum rooms where users can create a room about a topic, and chat with other users about it.

To share a bit of code, I'll share what my Book model looks like since it makes use of scope methods and the GoogleBooks API gem

    has_many :books_shelves 
    has_many :shelves, through: :books_shelves 
    has_many :users, through: :shelves
    has_many :books_authors
    has_many :authors, through: :books_authors

    scope :highest_rated, -> {where('average_rating >= ?', 4).sort}

    validates :title, presence: true 
    validates :isbn, presence: :true 
    validates :isbn, uniqueness: true 


    def most_pop
        average_rating.to_i * ratings_count.to_i
    end

    def self.highest_rated_sorted
        highest_rated.sort_by {|book| book.most_pop }
    end

    def self.search(search)
        book = GoogleBooks.search("#{search}", {count: 3 })
    end 
Enter fullscreen mode Exit fullscreen mode

Instead of using the GoogleBooks.search method all over my controllers, I decided to wrap it up into my own class method that would return exactly the amount of books I wanted. I also used a few different class methods and instance methods to sort books by rating and how many reviewers it has.

All in all, I'm excited to keep working on this project as it's been a huge learning journey. There are so many areas I'm dying to refactor and slim up, so I am looking forward to continuing to develop this app in the future!

Top comments (0)