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

  • SEARCH
  • Home
  • 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 6021499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:43:17+00:00 2026-05-23T03:43:17+00:00

I’m trying to get back into rails after a while and am having a

  • 0

I’m trying to get back into rails after a while and am having a tough time connecting two simple scaffold-built resources in a nested fashion. The parent controller works, but the child usually blows up. I’ve been looking all over for an answer to this problem, but haven’t succeeded.

For a specific comment child belonging to a product parent, route “/products/1/comments/1”

Error message

Couldn’t find Comment without an ID
app/controllers/comments_controller.rb:25:in `show’

Parameters:

{“product_id”=>”1”,
“id”=>”1”}

Here’s the relevant code from comments_controller “show”

def show
@product = Product.find(params[:product_id])
@comment = @product.comments.find(params[:comment_id])

(If I change :comment_id to just :id the new error is:)

Couldn’t find Comment with ID=1 [WHERE (comments.product_id = 1)]

{“product_id”=>”1”,
“id”=>”1”}

For comment index: /products/1/comments

Error info:

undefined method `model_name’ for Fixnum:Class
Parameters:
{“product_id”=>”1”}

** Relevant code from index view **

18:     <td><%= link_to 'Show', [@product, comment.id] %></td>
19:     <td><%= link_to 'Edit', edit_product_comment_path(@product, comment) %></td>
20:     <td><%= link_to 'Destroy', [@product, comment], :confirm => 'Are you sure?',           :method => :delete %></td>

I’ve spent a couple days messing with this to no avail. Been checking simple things like :id to :(noun)_id as well as switching between [@product, comment] and [@product, comment.id] in my view links.

Any suggestions are greatly appreciated on how to get this working. It seems like it should be simple, and I pretty much followed the “book.” The trouble with this is that my rails texts (The Rails way and a little ruby intro book with a couple chapters on rails) are based on rails 2 at best, and web resources haven’t been entirely updated.

Updates:
*Routes.rb*
Party2::Application.routes.draw do

resources :comments

resources :products do
  resources :comments
end

Errors from comment index

undefined method `model_name’ for Fixnum:Class

Relevant code from comment index (Error at line 18)

18:     <td><%= link_to 'Show', [@product, comment.id] %></td>
19:     <td><%= link_to 'Edit', edit_product_comment_path(@product, comment) %></td>
20:     <td><%= link_to 'Destroy', [@product, comment], :confirm => 'Are you sure?', :method => :delete %></td>

Another update:
*Models*

class Product < ActiveRecord::Base
  has_many :comments
end

class Comment < ActiveRecord::Base
  belongs_to :product
end

Thanks again,

Cameron

(Seems very strange to me that this shouldn’t work, as I’ve been following tutorials. :/)

  • 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-23T03:43:18+00:00Added an answer on May 23, 2026 at 3:43 am

    If a comment can belong to only one product, you should be able to do something like this in the comments_controller.rb:

    def show
      @comment = Comment.find(params[:id])
      # @product = @comment.product
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
Basically, what I'm trying to create is a page of div tags, each has
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.