Has_many class name not working as I thought?
I have a user and post model:
class User < ActiveRecord::Base
has_many :sent_posts, :class_name => 'Post'
end
class Post < ActiveRecord::Base
belongs_to :user
end
The problem is, in the console, if I do
User.first.sent_posts.empty?
it returns True.
But if I do it from my point of view
<%= @user.sent_posts.empty? %>
it returns False. Any idea why this is happening? It works great if I just use
has_many :posts
yourself.
thanks
0
source to share