Q:

undefined method `strftime' for nil:NilClass - shows sometimes

I'm building a simple app for displaying movies using themoviedb gem. However, when I try to do a search query, it displays the error I mentioned. Now, that doesn't happen every time - only in certain cases (e.g. Matrix works fine, but Fight Club shows the error)
Here's my code:
<% @movie.each do |movie| %>
<%= link_to movie_path(movie.id) do %>
<%= image_tag("#{@configuration.base_url}w154#{movie.poster_path}") if movie.poster_path %>
<% end %>
<div class="moviesindex">
<%= link_to movie.title, movie_path(movie.id) %>
(<%= movie.release_date.to_date.strftime("%Y") %>) <br />
</div>
<% end %>

A:

Be forgiving for realease_date if movie.release_date can be nil at times using try:
<%= movie.release_date.try(:year) %>

This will give you release year if release_date is valid and gives you nil if release_date is nil.
Since release_date, I assume is already either a Date or DateTime or ActiveSupport::TimeWithZone, the to_date is not necessary.  Also I think date.year is more cleaner than date.strftime("%Y").

