开发者

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 -%>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜