Reputation: 9499
Why is my code returning this error?
@articles = Article.order("id DESC").where(:visible => 1)
if @aritcles.size > 15
@articles = Article.order("id DESC").where(:visible => 1).limit(15)
end
returns:
undefined method `size' for nil:NilClass
If i run
@articles = Article.order("id DESC").where(:visible => 1)
@articles.size
It returns an integer...
Upvotes: 0
Views: 6634
Reputation: 160923
if @aritcles.size > 15
should be if @articles.size > 15
.
But your code is odd, it is not necessary to do that. Just do the below is enough.
@articles = Article.order("id DESC").where(:visible => 1).limit(15)
Upvotes: 3
Reputation: 13925
If that is from your real code, then you mispelled articles
to aritcles
.
If that is different, please provide the real code.
Upvotes: 3