Ruby on Rails Monday, November 23, 2015

dumb mistake in my example... Move the <h3> tags out of the erb insert...

<h2>Categories</h2>

<% @categories.group_by(&:parent_id).each do |parent_id, categories| %>

<h3>

   <%= parent_id%>

</h3>

<% categories.each do |category| %>

<%=    category.name %><br/>

<%  end %>

<% end %>




On Sunday, November 22, 2015 at 9:13:51 AM UTC-7, Allen Maxwell wrote:
Doing it this way seems to return an array of arrays where the 0 index is the index and the 1 index is the list of items in that group...

try doing something like this:

<h2>Categories</h2>

<% @categories.group_by(&:parent_id).each do |parent_id, categories| %>

<%= <h3>parent_id</h3> %>

<% categories.each do |category| %>

<%=    category.name %><br/>

<%  end %>

<% end %>







On Saturday, November 21, 2015 at 2:24:51 PM UTC-7, fugee ohu wrote:
<h2>Categories</h2>
<%= @categories.group_by(&:parent_id).each do |category| %>
 <%= category.name %><br>
<% end %>

This code results in ActionController returning
undefined method `name' for #<Array:0xb48bf628> 

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/8331ff96-7a8a-41f2-8c0c-38578505cad6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment