find conditions query
I have a transition. I would like to say that if the last transition (model: DistributionSheet, attribute:state) is closed, then display these results.开发者_如何学Go So I need this:
WHEN:
<% DistributionSheet.find(:all, :conditions => ["state = ?","closed"]).last %>
THEN:
<% Result.find(:all).each do |result| %>
<%= result.name %>
<% end %>
Something like that. Can anyone direct me please. Thanks Ali
You shouldn't be doing this stuff in your view, but that's another matter :-)
Is this what you mean? ...
<% if DistributionSheet.find(:last).state == "closed" %>
<% Result.find(:all).each do |result| %> <%= result.name %> <% end %>
<% end %>
Why not just do it as an if?
<%- if (DistributionSheet.where(:state => 'closed').last) -%>
<% Result.all.each do |result| %>
<%= result.name %>
<% end %>
<%- end -%>
Update: Alternate interpretation of the question:
<%- if (DistributionSheet.last.state == 'closed') -%>
<% Result.all.each do |result| %>
<%= result.name %>
<% end %>
<%- end -%>
精彩评论