[Rails] UNCLE!!!

Ben Schumacher benschumacher at gmail.com
Tue Feb 1 00:56:40 GMT 2005


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 at mw.merseine.nu> 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 at lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


More information about the Rails mailing list