尝试将对象存储在数组中以在视图中进行迭代。
在我的控制器中:
def expire
@search = Search.new(search_params)
if @search.valid?
@clients = []
@allClients = #value from REST API
@allClients.each do |client|
@clientele = Clientele.new
@clientele["exp"] = client.experience ##Also tried @clientele.exp = client.experience
@clientele["email"] = client.email ##Also tried @clientele.email = client.email
@clients.push(@clientele)
end
end
end
class Clientele
def exp
end
def email
end
end
在我看来,什么都没有显示,并且显示 @clients 数组会给出一个空数组:
<% @clients.each do |client| %>
<%= client.exp %>
<%= client.email %>
<% end %>
<%= clients %> #=> []
我不确定我做错了什么,我似乎不能只创建一个临时对象来存储值并将其存储到数组中。任何帮助或建议都会有所帮助。