Complete Lesson 7

main
Simon Quigley 1 year ago
parent 9b03bbd714
commit eb029fb99b

@ -1,2 +1,13 @@
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

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

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

Loading…
Cancel
Save