How to make an SQL querey Within a partial, is that possilbe?

Hello,
I’m quite new to Rails and english is even not my first language, so
please excused nescience and clerical mistake.
I’ll try to explain my problem as good as possible.

I try to implement a page where a profil is shown, this is searched by
ID.
within this profil page I want to include the comments that refer to
this profil.
In the back I have to database tabels, the one “profiles” and a second
“comments”.
In the second one I ve the column “profil_id” because my Idea was to
search for the Id of the profil which is shown and than to display the
comments in which the profil_id is the same.

I already tried to implement this Idea but I hit some problems:

the profil page works fine.

show.erb.html:


Titel


<%= h @profil.title %>







<%= h @profil.subtitle %>



         ......
         ......
         ....

        <div style="width: 500px; margin-top: 20px;">
<h2>Kommentare</h2>
<%= render :partial => "comments/

comments_show", :locals=>{:profil_id=>@profil.id} %>

and there I tried to call a partial which display the comments…
And that my problem…
I hand over the profil_id (which works fine) but I ve NO idea how and
where to include the Search to find the comments with the same id…

in the file _comments_show.erb.html i ll tried something like that:

I JUST MISS THE END , sorry
Hello,
I’m quite new to Rails and english is even not my first language, so
please excused nescience and clerical mistake.
I’ll try to explain my problem as good as possible.

I try to implement a page where a profil is shown, this is searched by
ID.
within this profil page I want to include the comments that refer to
this profil.
In the back I have to database tabels, the one “profiles” and a second
“comments”.
In the second one I ve the column “profil_id” because my Idea was to
search for the Id of the profil which is shown and than to display the
comments in which the profil_id is the same.

I already tried to implement this Idea but I hit some problems:

the profil page works fine.

show.erb.html:


Titel


<%= h @profil.title %>







<%= h @profil.subtitle %>



         ......
         ......
         ....

        <div style="width: 500px; margin-top: 20px;">
            <h2>Kommentare</h2>
            <%= render :partial => "comments/

comments_show", :locals=>{:profil_id=>@profil.id} %>

and there I tried to call a partial which display the comments…
And that my problem…
I hand over the profil_id (which works fine) but I ve NO idea how and
where to include the Search to find the comments with the same id…

in the file _comments_show.erb.html i ll tried something like that:
<%= h @comment.title %>
but that doesnt work.

Please help

On Jun 6, 8:54 am, happysmiley [email protected] wrote:

In the back I have to database tabels, the one “profiles” and a second
“comments”.
In the second one I ve the column “profil_id” because my Idea was to
search for the Id of the profil which is shown and than to display the
comments in which the profil_id is the same.

You should have an association between profiles and comments (profile
has_one :comment or has_many :comments) and then profile.comment or
profile.comments will be the comment(s) you are looking for

Fred