Ok, I ALMOST made it through adding comments to my blog without asking for help. I think I need some clause for find_all that allows me to say something like find_all(post_id), where post id is the value of the post_id field in the post row associated with the comments I''m attempting to retrieve and process. I have it all working, if a little roughly, except that my retrieval loop retrieves all comments. Can someone point to the place things like find_all are documented? I hate to keep running to the list with trivialities I''m capable referencing for myself :) Thanks! Twitch
I would imagine that you have some sort of relationship setup, right? Something like: class BlogEntry has_many :comments end Which would allow a controller (we''ll call the view comments/<blog entry #>) to do something like: class BlogController def comments @entry = BlogEntry.find(1) end end With a view like: <% @entry.comments.each { |comment| %> ... <% end %> If you''re not doing your relationships like that, you could also reference it using: find_by_post_id(#); Assuming the table that contains your comments users the column "post_id" as the associative key. Cheers, Ben On Mon, 31 Jan 2005 18:47:59 -0600, James G. Stallings II <twitch-kuaf+BvAnvdypLqBFPtG/w@public.gmane.org> wrote:> Ok, I ALMOST made it through adding comments to my blog without asking > for help. > > I think I need some clause for find_all that allows me to say something > like find_all(post_id), where post id is the value of the post_id field > in the post row associated with the comments I''m attempting to retrieve > and process. > > I have it all working, if a little roughly, except that my retrieval > loop retrieves all comments. > > Can someone point to the place things like find_all are documented? I > hate to keep running to the list with trivialities I''m capable > referencing for myself :) > > Thanks! > Twitch > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Are you looking for http://api.rubyonrails.com? Here''s what they have to say about find_all there: find_all(conditions = nil, orderings = nil, limit = nil, joins = nil) Returns an array of all the objects that could be instantiated from the associated table in the database. The conditions can be used to narrow the selection of objects (WHERE-part), such as by "color ''red''", and arrangement of the selection can be done through orderings (ORDER BY-part), such as by "last_name, first_name DESC". A maximum of returned objects and their offset can be specified in limit (LIMIT…OFFSET-part). Examples: Project.find_all "category = ''accounts''", "last_accessed DESC", 15 Project.find_all ["category = ?", category_name], "created ASC", ["? OFFSET ?", 15, 20] On Mon, 31 Jan 2005 18:47:59 -0600, James G. Stallings II <twitch-kuaf+BvAnvdypLqBFPtG/w@public.gmane.org> wrote:> Ok, I ALMOST made it through adding comments to my blog without asking > for help. > > I think I need some clause for find_all that allows me to say something > like find_all(post_id), where post id is the value of the post_id field > in the post row associated with the comments I''m attempting to retrieve > and process. > > I have it all working, if a little roughly, except that my retrieval > loop retrieves all comments. > > Can someone point to the place things like find_all are documented? I > hate to keep running to the list with trivialities I''m capable > referencing for myself :) > > Thanks! > Twitch > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Hey Thanks guys that gives me a lot to work with. I''ll see if I can''t Git ''Er Done. ;P Thanks for the pointer to the api doc Duane :) Cheers! Twitch
Duane Johnson wrote:>Are you looking for http://api.rubyonrails.com? > >Here''s what they have to say about find_all there: > >find_all(conditions = nil, orderings = nil, limit = nil, joins = nil) > >Returns an array of all the objects that could be instantiated from >the associated table in the database. The conditions can be used to >narrow the selection of objects (WHERE-part), such as by "color >''red''", and arrangement of the selection can be done through orderings >(ORDER BY-part), such as by "last_name, first_name DESC". A maximum of >returned objects and their offset can be specified in limit >(LIMIT…OFFSET-part). Examples: > > Project.find_all "category = ''accounts''", "last_accessed DESC", 15 > Project.find_all ["category = ?", category_name], "created ASC", ["? >OFFSET ?", 15, 20] > > > >On Mon, 31 Jan 2005 18:47:59 -0600, James G. Stallings II ><twitch-kuaf+BvAnvdypLqBFPtG/w@public.gmane.org> wrote: > > >>Ok, I ALMOST made it through adding comments to my blog without asking >>for help. >> >>I think I need some clause for find_all that allows me to say something >>like find_all(post_id), where post id is the value of the post_id field >>in the post row associated with the comments I''m attempting to retrieve >>and process. >> >>I have it all working, if a little roughly, except that my retrieval >>loop retrieves all comments. >> >>Can someone point to the place things like find_all are documented? I >>hate to keep running to the list with trivialities I''m capable >>referencing for myself :) >> >>Thanks! >>Twitch >>_______________________________________________ >>Rails mailing list >>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > > >From a newbie, but couldn''t you just use: Project.find_all_by_post_id(''condition'')
> From a newbie, but couldn''t you just use: > > Project.find_all_by_post_id(''condition'') > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/railsYeah that approximates what I have going now, but for some reason the search returns an empty set (nil object). I''m trying to figure out why now Thanks for the suggestion, its on target :) Twitch
Twitch, I''m using http://rails.rubyonrails.com as my reference. It''s exactly the same as api.rubyonrails.com, except that it doesn''t have the rubyonrails.com navigation bar eating up precious space. As for your problem, I assume you have a @blogpost object at hand any way. In that case it''s most elegant to use the @blogpost.comments array, just like Ben suggested. It uses the object-oriented magic Rails provides you so you don''t have to reach for explicit find-methods. //jarkko On 1.2.2005, at 05:48, James G. Stallings II wrote:> >> From a newbie, but couldn''t you just use: >> >> Project.find_all_by_post_id(''condition'') >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails > > > Yeah that approximates what I have going now, but for some reason the > search returns an empty set (nil object). > > I''m trying to figure out why now > > Thanks for the suggestion, its on target :) > > Twitch > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
To answer a question with a question: Do you have any reason to believe the search should _not_ return an empty set? (Copy the query from the log and see what you get -- "Use the Logs, Luke") Also, do you mean a ruby nil, or an empty array? On Mon, 31 Jan 2005 21:48:56 -0600, James G. Stallings II <twitch-kuaf+BvAnvdypLqBFPtG/w@public.gmane.org> wrote:> > > From a newbie, but couldn''t you just use: > > > > Project.find_all_by_post_id(''condition'') > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > Yeah that approximates what I have going now, but for some reason the > search returns an empty set (nil object). > > I''m trying to figure out why now > > Thanks for the suggestion, its on target :) > > Twitch > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- This is my sig. Isn''t it cool....
Jarkko Laine wrote:> I''m using http://rails.rubyonrails.com as my reference. It''s exactly the > same as api.rubyonrails.com, except that it doesn''t have the > rubyonrails.com navigation bar eating up precious space.Just as an FYI, I''ve noticed that http://api.rubyonrails.org/ seems to be outdated (last changed Thu Dec 16 2004). http://rails.rubyonrails.org/ has the most recent version of the API. Maybe the old uri should be removed, or at least issue a 301 to help avoid confusion from people using outdated docs? /Jeff
> Jarkko Laine wrote: > Maybe the old uri should be removed, or at least issue a 301 to help > avoid confusion from people using outdated docs?I would pref. if DHH just redirected the users from api.rubyonrails.org to rails.rubyonrails.org - Warren
On Feb 1, 2005, at 19:41, wn-cJcUr56/Xx3QT0dZR+AlfA@public.gmane.org wrote:>> Jarkko Laine wrote: >> Maybe the old uri should be removed, or at least issue a 301 to help >> avoid confusion from people using outdated docs? > > I would pref. if DHH just redirected the users from > api.rubyonrails.org to > rails.rubyonrails.orgDavid? Please? It''s not the first time this is causing confusion. Regards, Thijs -- Fingertips - http://www.fngtps.com Firefox - Take back the web - http://getfirefox.com
* Thijs van der Vossen <t.vandervossen-d8uFP1XuNEbQT0dZR+AlfA@public.gmane.org> [0219 09:19]:> > On Feb 1, 2005, at 19:41, wn-cJcUr56/Xx3QT0dZR+AlfA@public.gmane.org wrote: > > >>Jarkko Laine wrote: > >>Maybe the old uri should be removed, or at least issue a 301 to help > >>avoid confusion from people using outdated docs? > > > >I would pref. if DHH just redirected the users from > >api.rubyonrails.org to > >rails.rubyonrails.org > > David? Please? It''s not the first time this is causing confusion.Can''t they just be CNAMEd/ServerAliased to the .com sites? They seem to do things the right way (api.rubyonrails.com just points to rails.rubyonrails.com in the bottom frame). -- ''Everybody I know who is right always agrees with ME.'' -- Rev Lady Mal Rasputin :: Jack of All Trades - Master of Nuns