Ruby on rails 三元结构中块的rails语法

Ruby on rails 三元结构中块的rails语法,ruby-on-rails,ternary,Ruby On Rails,Ternary,我在视图中嵌套了循环块,次块中有三元。这会引发语法错误,意外的关键字_do_block,应为“:” <% @teams.each do |team| %> some html <% @account.some_attribute true? ? team.users.with_option.sort_lastname.each do |user| : team.users.active.sort_lastname.each do |user] %> so

我在视图中嵌套了循环块,次块中有三元。这会引发语法错误,意外的关键字_do_block,应为“:”

<% @teams.each do |team| %>
  some html
  <% @account.some_attribute true?  ? team.users.with_option.sort_lastname.each do |user| : team.users.active.sort_lastname.each do |user] %>
    some html
  <% end %>
<% end %>

一些html
一些html

是否有正确的语法,或者我应该找到另一种方法?

不,您应该执行以下操作

您应该为ex:-
users
获取某个_变量中的用户数组,然后在其上迭代循环

像这样的

<% @teams.each do |team| %>
  some html
  <% users =  @account.some_attribute true?  ? team.users.with_option.sort_lastname : team.users.active.sort_lastname
   users.each do |user| %>
    some html
  <% end %>
<% end %>

一些html
一些html

这太难看了,你想做什么?@MarekLipka:我想他试图用两个不同的方法调用同一个块,有条件地选择。我需要根据@account.some_属性值在我的块中调用两个不同的作用域。我修复了问题中从原始代码复制的明显错误+1.如果
@account.some_属性
始终返回一个
true/false/nil
您可以将您的条件更改为以下
users=@account.some_属性?team.users.with_option.sort_lastname:team.users.active.sort_lastname
是的,这样做有效。我没有想到要拆分语法。谢谢