How do I limit/restrict a results set?

Simple question. I’m a newbie with rails and just need to restrict the
results of a query (a where clause in SQL). I am building a simple
application that enables the user to add pages and post comments to each
page. I have build a table for pages and posts and have related the two
models (one page to many posts). When a user is on a page, I just want
the list of posts to be restricted to the posts made for that particular
page. Here is what it would look like in SQL:

select * from posts where posts.pageid = {this.pageid}

What should the syntax look like? Where would I restrict the results (in
the controller or the model)?

Thanks.

you mean using

LIMIT 10 OFFSET 20 in sql

or

:limit => 10 in .find ?

Thanks for replying. Limit was probably a poor choice of words. The SQL
equivalent of what I’m referring to is the WHERE clause.

select * from posts where posts.pageid = {this.pageid}

Worked! Thx.

so you want maybe:

:conditions => [“posts.pageid = ?”, this.pageid]

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