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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
you mean using LIMIT 10 OFFSET 20 in sql or :limit => 10 in .find ? Jed Meade wrote:> 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. > > -- > Posted via http://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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} -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
so you want maybe: :conditions => ["posts.pageid = ?", this.pageid] -- -- wrote:> 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} > > -- > Posted via http://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Worked! Thx. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---