Returning Count from find_by_sql

I want to return an int from a find_by_sql call. But when I use that
result to compare to another count the error tells me I have an array.

MODEL:

# Returns the number of comments in a specified post
def self.find_count(post_id)
    find_by_sql(["SELECT COUNT(*) FROM commments WHERE post_id = ?",
                post_id])
end

CONTROLLER:

def test
@post = Post.find(@params[“post_id”])
@comment =
Comment.find_next(@params[“post_id”], @params[“position”])
@count = Comment.find_count(@params[“post_id”])
end

VIEW:

line 1: <% if @comment.position < @count -%>

ERROR:

ActionView::TemplateError (comparison of Fixnum with Array failed) on
line #1 of app/views/main/_test.rhtml:

Do I have a syntax error?

Will M. wrote:

I want to return an int from a find_by_sql call. But when I use that
result to compare to another count the error tells me I have an array.

Use count_by_sql instead.


We develop, watch us RoR, in numbers too big to ignore.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs