happysmiley
2010-Jun-06 07:52 UTC
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: <tr> <td class="headline">Titel</td> <td> <div class="table-col"> <%= h @profil.title %> </div> </td> </tr> <tr> <td class="headline"></td> <td> <div class="table-col"> <%= h @profil.subtitle %> </div> </td> </tr> <tr> ...... ...... .... <div style="width: 500px; margin-top: 20px;"> <h2>Kommentare</h2> <%= render :partial => "comments/ comments_show", :locals=>{:profil_id=>@profil.id} %> </div> 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: -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
happysmiley
2010-Jun-06 07:54 UTC
Re: How to make an SQL querey Within a partial, is that possilbe??
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: <tr> <td class="headline">Titel</td> <td> <div class="table-col"> <%= h @profil.title %> </div> </td> </tr> <tr> <td class="headline"></td> <td> <div class="table-col"> <%= h @profil.subtitle %> </div> </td> </tr> <tr> ...... ...... .... <div style="width: 500px; margin-top: 20px;"> <h2>Kommentare</h2> <%= render :partial => "comments/ comments_show", :locals=>{:profil_id=>@profil.id} %> </div> 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 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Jun-06 09:53 UTC
Re: How to make an SQL querey Within a partial, is that possilbe??
On Jun 6, 8:54 am, happysmiley <toniz...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> 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 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.