[Rails] Re: .empty? Method
by Michael Boutros other posts by this author
Feb 11 2006 5:52PM messages near this date
Re: [Rails] .empty? Method
|
Re: [Rails] Re: .empty? Method
Nick Stuart wrote:
> 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
No, I am doing a view page to view an entry seperately. I am using the
.empty? method to check if the row exists, and if it does not I will
output an error. This is the entire page code:
class PostsController < ApplicationController
def index
@posts = Posts.find_all
end
def view
@post = Posts.find(@params["id"])
if @post.empty?
render_text "Post does not exist."
end
end
end
--
Posted via http://www.ruby-forum.com/.
_______________________________________________
Rails mailing list
Rails@[...].org
http://lists.rubyonrails.org/mailman/listinfo/rails
Thread:
Michael Boutros
Nick Stuart
Michael Boutros
Brian V. Hughes
|