When the logged-in user clicks the 'Find Top Rated Movies' button, they will then see the top 40 movies.
Each movie has:
a title that is a link to that movie's show page
the vote average for that movie
Private Methods
The methods in here all adhere to SRP and can be encapsulated into a different class or classes eventually.
For now, I am hiding them away to keep our controller action at a high level of abstraction:
def index
@movies = top_rated_movies if params[:q] == 'top rated'
end
Exception Handling
I used exception handling to solve the issues I documented regarding the TMDB server response format.
It is implemented with rescue statements and guard clauses and a sad view path.
The first rescue handles the edge case where the server is responding with HTML instead of JSON:
def valid_json?(string)
JSON.parse(string)
rescue JSON::ParserError
false
end
The second rescue will then assign nil to @movies in the index action.
def top_rated_movies
...
rescue NoMethodError
nil
end
That allows for the sad view path (necessary to pass tests and CI checks):
<% if @movies.nil? %>
<% 40.times do %>
<%= tag.article class: "movie" %>
<% end %>
<% else %>
...
New Feature: Top Rated Movies
When the logged-in user clicks the 'Find Top Rated Movies' button, they will then see the top 40 movies. Each movie has:
Private Methods
The methods in here all adhere to SRP and can be encapsulated into a different class or classes eventually. For now, I am hiding them away to keep our controller action at a high level of abstraction:
Exception Handling
I used exception handling to solve the issues I documented regarding the TMDB server response format. It is implemented with
rescue
statements and guard clauses and a sad view path.The first rescue handles the edge case where the server is responding with HTML instead of JSON:
The second rescue will then assign nil to @movies in the index action.
That allows for the sad view path (necessary to pass tests and CI checks):