Complete Lesson 7

main
Simon Quigley 1 year ago
parent 9b03bbd714
commit eb029fb99b

@ -1,2 +1,13 @@
module MoviesHelper module MoviesHelper
def total_gross(movie)
if movie.flop?
"Flop!"
else
number_to_currency(movie.total_gross, precision: 0)
end
end
def year_of(movie)
movie.released_on.year
end
end end

@ -1,2 +1,5 @@
class Movie < ApplicationRecord class Movie < ApplicationRecord
def flop?
total_gross.blank? || total_gross < 225_000_000
end
end end

@ -5,8 +5,8 @@
<ul> <ul>
<% @movies.each do |movie| %> <% @movies.each do |movie| %>
<li><%= movie.title %> (<%= movie.rating %>, <%= movie.released_on %>): <%= number_to_currency(movie.total_gross, precision: 0) %> <li><%= movie.title %> (<%= movie.rating %>, <%= year_of(movie) %>): <%= total_gross(movie) %>
<br /><i><%= movie.description %></i> <br /><i><%= truncate(movie.description, length: 40, separator: "") %></i>
</li> </li>
<% end %> <% end %>
</ul> </ul>

Loading…
Cancel
Save