Saturday, 31 August 2013

How to create liking/favorites system in rails?

How to create liking/favorites system in rails?

A bit of a rails noobie here.
I'm building a simple rails app that lets you discover books.
My models are Book and User.
One of the main features is to be able to like/favorite books.
I would like to to be structured like this.
There is a favorite button for each book.
Every time a unique user clicks the button, two things will happen.
1)The score for book goes up by +1 (the score should update in the view
right away)
2)This specific book will be added to a list of favorites for that
specific user.
What is the simplest and least messy way to achieve this?
Please be descriptive. Should I have an attribute called score for each
book? Should I have an attribute called favorites for each user?
What should the code look like in the Model, Controller and View?
I'd like to avoid using a gem here, I would just like a super simple
implementation.
Thanks!

No comments:

Post a Comment