On May 2, 2006, at 01:35 PM, ben wrote:
@cat1 = Link.find(:all, :conditions => "category = ‘1’ ")
Key point, when you do a find :all, what you get back is an Array. So
what you need to test for is whether the array is empty.
the “<% if @cat1 != “” %>” is the part I cannot figure out how to say.
Change that line to: “<% unless @cat1.empty? %>”. This way you are
telling Ruby to evaluate the block only when @cat1 has items to
process. Of course, you don’t really need to do this in this way. I
would actually eliminate the unless block altogether. The “for link
in @cat1” loop statement will simply not fire if @cat1 is empty.
So that just leaves the Building Regulations line. I would probably
change that to:
<%= @cat1.empty? ? “” : “Building Regulations
And if you’re OK with that, the next step would be to replace the for
<%= render :partial=>“link”, :collection => @cat %>
That will really clean up your view code.