开发者

find conditions query

开发者 https://www.devze.com 2023-02-21 02:59 出处:网络
I have a transition.I would like to say that if the last transition (model: DistributionSheet, attribute:state) is closed, then display these results.开发者_如何学GoSo I need this:

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

精彩评论

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

关注公众号