How to return ActiveRecord proxy server to ERB

so I have a standard has_many through an association in my models, very similar to the question here: Loop through ActiveRecord :: Associations :: CollectionProxy with each

I used the advice in this problem, but I think that I am having problems attaching it to the ERB file so that it appears in my application. At the moment, I have the following:

<%= @memberships.map do |a| %>
<%=a.name%>
<% end %>

In this scenario, the membership model is one in which users and organizations have a lot (@memberships = @ user.organizations). So @ memberships.class returns

ActiveRecord::Associations::CollectionProxy::ActiveRecord_Associations_CollectionProxy_Organization

on the rail console. So, at the moment in the browser, the code is returning to the page where the user is in two organizations:

orgone orgtwo["\n", "\n"]

, -, , . !

UPDATE:

, = , :

<% @memberships.map do |a| %>
<h3><%=a.name %> <%= ", " unless a == @memberships.last %></h3>
<% end %>
+4
1

,

<% @memberships.each do |membership| %>
   <%= membership.name %>
<% end -%>

<% ERB , <%= . , a <%= , - #<Enumerator:0xDEADBEEF.

+2

Source: https://habr.com/ru/post/1524397/


All Articles