title: Rails count number of Users who favorited Post
body: <p>Relatively new to rails, and am just trying to sort through my model relationships in order to find the number of users who have Favorited a particular post. Here are my models:</p>
  
  <p>User.rb</p>
  
  <pre><code>has_many :favorites
  has_many :favorite_posts, through: :favorites, source: :favorited, source_type: 'Post'
  </code></pre>
  
  <p>Post.rb</p>
  
  <pre><code>  belongs_to :user
    has_many :favorites
  </code></pre>
  
  <p>Favorite.rb</p>
  
  <pre><code>belongs_to :favorited, polymorphic: true
  belongs_to :user
  </code></pre>
  
  <p>In my Posts#show view I want to call something like</p>
  
  <pre><code>&lt;%= @post.favorited.count %&gt; 
  </code></pre>
  
  <p>and get the number of users who have favorited this post, but it tells me that this is an undefined method. </p>
  
  <p>Any suggestions? thank you,</p>