[Rails] .empty? Method

Nick Stuart nicholas.stuart at gmail.com
Sun Feb 12 01:45:50 GMT 2006


It looks like you are calling it on a Post object, where the .empty is
meant for collections/strings and such. Should the above line read,
if @posts.empty?
..

Notice the s. I'm guessing you are loading posts like:
@posts = Post.find(:all)?

if so then @posts.empty? should work just fine.

-Nick

On 2/11/06, Michael Boutros <me at michaelboutros.com> wrote:
> I am using:
>
>     if @post.empty?
>        render_text "Post does not exist."
>     end
>
> But it gives me this error:
>
> NoMethodError in Posts#view
>
> undefined method `empty?' for #<Posts:0x39598d0>
>
> However, if the method list empty? apears and stuff so I am confused.
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails at lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


More information about the Rails mailing list