Problems select correct records from 2 tables

def show
  @news = News.find(params[:id])
end

And then in your view, eg.:

<% @news.comments.each do |comment| %>
<p>
  <%= comment.message %>
</p>
<hr/>
<% end %>

Assuming that your comments.approved column is a boolean, you can do this:

class News < ActiveRecord::Base
   has_many :approved_comments, :class_name => 'Comment', :conditions => ['approved = ?', true]
end
class Comment < ActiveRecord::Base
   belongs_to :news
end

Doing it this way should be correct for any database (even when boolean is implemented by 0/1).

Then in your controller:

def show
   @news = News.find( params[:id] )
   @comments = @news.approved_comments # or just do this in your view
end

And your view:

<ul>
<% for comment in @news.approved_comments -%>
   <li><%= comment.body %></li>
<% end -%>
</ul>

Of course, your markup is whatever you prefer and I've guessed that the interesting piece from a comment is in a "body" column, but this should help you out.

-Rob

Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com

I see. Then I would do this (you may need to change the condition):

class News
  has_many :comments do
    def approved
      @approved_comments ||= find(:all, :conditions => 'is_approved IS
TRUE')
    end
  end

  #The rest of the class News...
end

And in your view:

<% @news.comments.approved.each do |comment| %>
<p>
   <%= comment.message %>
</p>
<hr/>
<% end %>

Br,

Morten