Hello i have some categories that im trying to display using the in_groups_of rails method
I get this error and i can't figure out why. I've only been learning rails for 3 months.
NoMethodError in Categories#show
undefined method `name' for #<Array:0x007fe6d3adf360>
<% @category.children.in_groups_of(4, false) do |category| %>
<li>
<%= link_to_unless_current category.name, category %>
</li>
<% end %>
</ul>
Im using Acestry Gem so the name method is part of the gem. http://ift.tt/Sbirff
Here is my Show View. Its very simple
<p id="notice"><%= notice %></p>
<ul>
<% @category.ancestors.each do |category| %>
<%= link_to category.name, category %> >
<% end %>
</ul>
<h2>
<strong><%= @category.name %></strong>
</h2>
<h2>
<strong><%= @category.name %></strong>
</h2>
<ul>
<% @category.children.in_groups_of(4, false) do |category| %>
<li>
<%= link_to_unless_current category.name, category %>
</li>
<% end %>
</ul>
Category controller.
class CategoriesController < ApplicationController
before_action :set_category, only: [:show, :edit, :update, :destroy]
def index
@categories = Category.all
end
def show
end
def new
@category = Category.new
end
def edit
end
def create
@category = Category.new(category_params)
respond_to do |format|
if @category.save
format.html { redirect_to @category, notice: 'Category was successfully created.' }
format.json { render :show, status: :created, location: @category }
else
format.html { render :new }
format.json { render json: @category.errors, status: :unprocessable_entity }
end
end
end
def update
respond_to do |format|
if @category.update(category_params)
format.html { redirect_to @category, notice: 'Category was successfully updated.' }
format.json { render :show, status: :ok, location: @category }
else
format.html { render :edit }
format.json { render json: @category.errors, status: :unprocessable_entity }
end
end
end
def destroy
@category.destroy
respond_to do |format|
format.html { redirect_to categories_url, notice: 'Category was successfully destroyed.' }
format.json { head :no_content }
end
end
private
def set_category
@category = Category.find(params[:id])
end
def category_params
params.require(:category).permit(:name, :parent_id)
end
end
Aucun commentaire:
Enregistrer un commentaire