Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 376121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:34:06+00:00 2026-05-12T14:34:06+00:00

I am trying to follow Ryan Bates screencast but have an error message. I

  • 0

I am trying to follow Ryan Bates screencast but have an error message. I did the following:

1) Create table

class CreateComments < ActiveRecord::Migration
  def self.up
    create_table :comments do |t|
      t.references :commentable, :polymorphic => true

2) Setup models

class Comment < ActiveRecord::Base
  belongs_to :commentable, :polymorphic => true

class Product < ActiveRecord::Base
  has_and_belongs_to_many :categories
  has_many :comments, :as => :commentable

class Category < ActiveRecord::Base
  has_and_belongs_to_many :products
  has_many :comments, :as => :commentable

3) Change controller show action

class CategoriesController < ApplicationController
  def show
    @category = Category.find_by_permalink(params[:id])
    @commentable = @category
    @comment = Comment.new(:commentable => @category)
  end

4) Add a form to template views/categories/show.html.erb

<% form_for [@commentable, Comment.new] do |f| %>
  <p>
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </p>
  <p>
    <%= f.label :content %><br />
    <%= f.text_area :content %>
  </p>
  <p>
    <%= f.submit 'Submit' %>
  </p>
<% end %>

5) After that I get error message by accessing /categories/my-category-permalink

NoMethodError in Categories#show
undefined method `category_comments_path' for #<ActionView::Base:0x69a9254>

Could you help me to understand what I did wrong?
In the original screencast Ryan accesses comments by /categories/permalink/comments using nested associations, but I don’t need that. I want to write comments directly from my polymorphic objects.
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T14:34:06+00:00Added an answer on May 12, 2026 at 2:34 pm

    The problem was in routes settings. I thought that since I don’t use nested resources, I can keep routes unchanged. Well, now I know that I was wrong… 🙂 Add this to fix the problem:

    map.resources :categories :has_many => :comments
    map.resources :products, :has_many => :comments
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to follow a technique found at bzr and gitosis I did the following:
I am trying to follow the steps on the following site http://msdn.microsoft.com/en-us/library/ms181089(VS.80).aspx But I
Trying to follow this tutorial. Autotest fails with this error message: sg $autotest loading
I have been trying to follow the few tutorials on how to create a
I'm trying follow a tutorial to create a custom USB driver in Linux and
Trying to follow the hints laid out here , but she doesn't mention how
I'm trying to follow the advice of the sage Answermen re: moving my class
I'm trying to follow Michael Hartl's Ruby on Rails Tutorial in http://ruby.railstutorial.org/chapters/sign-in-sign-out , but
I'm trying to follow who my friend is following (all 1,522 of them) and
I am trying to follow the example here ...but get the exception: 'System.Uri' does

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.