Answer the question
In order to leave comments, you need to log in
How to correctly create percentage progress for something?
Let's say you need to calculate how many pages were read as a percentage and display it as a progress bar.
My thoughts:
1. Add a progress:integer and pages:integer column to the Book.rb model
2. Let's say we create a book and write 700 pages.
3. Display the progress in the view like this:
<% @progress = @user.progress.count/pages.count * 100 %>
Answer the question
In order to leave comments, you need to log in
Book.rb
def percentage
(progress.to_f / pages * 100).round
end
books.first
, you need the right condition by which to select a particular book.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question