Error with shout.content - nil ActiveModel-compatible object

I’m getting the following error with when trying while trying to implement photo_shout:

'nil' is not an ActiveModel-compatible object. It must implement :to_partial_path.

The template is for _shout.html.erb under views > shouts:

<div class="shout">
  <%= link_to shout.user.username, shout.user %>
  shouted
  <%= render shout.content %>
  <%= link_to time_ago_in_words(shout.created_at), shout %>
</div>

I saw this in a couple of different places on this forum, and everyone seemed to fix it by re-installing imagemagick or restarting their computer (tried both).

Everything seems to be working fine when I reset my database and try to log in as a new user. As soon as I try to create a photo_shout though, everything breaks.

Any ideas??

Fixed my own error

There were some orphaned photo_shouts in my database. Not sure why I wasn’t able to fix this the first time with a db:reset. Added this to my shouts.rb model based on someone else’s suggestion in this forum.

  belongs_to :user, required: true
  belongs_to :content, polymorphic: true, required: true, dependent: :destroy
  validate :content_must_be_valid
  default_scope { order("created_at DESC") }

  protected
  def content_must_be_valid
    if content && content.invalid?
      content_errors = content.errors.full_messages.join(", ")
      errors.add(:content, "not valid: #{content_errors}")
    end
  end

Ran into a different error afterwards:

Paperclip::Errors::NotIdentifiedByImageMagickError

Fixed this by running:

brew uninstall imagemagick jpeg libtiff --force libtiff

Then reinstalling imagemagick:

brew install imagemagick