2009/9/17 Dudebot <[email protected]>:
>
> Thanks super, Greg, for helping me out. I'm dense, 'cause I couldn't
> figure out the syntax for 'whatever'. I did get this to work in
> the .erb file:
>
> <% if Item.find( item ).orders.size > 0 %>
What is item here, is it already an Item object? If so then all you need is
if item.orders.empty?
No need to find it again.
Arguably better would be to provide a method in Item, possibly
'orders?' that indicates whether that item has any orders. Then you
would use
if item.orders?
where method orders? of Item returns self.orders.empty?
This moves logic from the view into the model which is often worthwhile.
Whenever I see a.b.c I consider whether something should be moved into a model.
Colin
> <%=h "Found #{item.title} in Orders" %>
> <% end %>
>
> But I'm just wondering... is that the most efficient way to do it? Is
> there a more efficient way?
>
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---