I am a newbie and I am working on a scaffold category for pins on a rails app. I have managed to assign a category to each new pin now, but how do I set it up so that when I go look at a certain specific category (ie. "cars"), it will automatically render all the pins in that "cars" category?
I have tried the codes similar to rendering pins of a specific user (ie. "user/1">, but that didn't work for categories, so how should I do it? Any help will be appreciated.
Here are my codes
view.categories.show.html.erb
<p id="notice"><%= notice %></p>
<h1>
<b>Category</b>
<%= @category.name %>
</h1>
<div id="pins">
<%= render @pins %>
</div>
<%= will_paginate @pins %>
my categories_controller.rb
def show
@category = Category.find(params[:id])
@pins = @category.pins.page(params[:page]).per_page(50)
respond_to do |format|
format.html # show.html.erb
format.json { render json: @category }
end
end
And it returns the below
ArgumentError in Categories#show
Showing /Users/mattbook/code/starsworthy/app/views/categories/show.html.erb where line #9 raised:
'nil' is not an ActiveModel-compatible object that returns a valid partial path.
Extracted source (around line #9):
Should I generate a partial like _pin.html.erb? how should I a approach that? Thanks in advance.
Categories_controller.rb
def show
@category = Category.find(params[:id])
@pins = @category.pins.page(params[:page]).per_page(50)
respond_to do |format|
format.html # show.html.erb
format.json { render json: @category }
end
end