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 8968873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:30:50+00:00 2026-06-15T17:30:50+00:00

I am experimenting with nested resources: My routes: resources :conversations do resources :replies do

  • 0

I am experimenting with nested resources:

My routes:

  resources :conversations do
    resources :replies do
      resources :comments
    end
  end

I was able to get the form for replies to work with the conversation, but now I’m adding the additional complexity of getting comments to work with replies.

The entirety of the forms are all under the conversation show path.

<%= form_for([@conversation, @reply]) do |f| %>
    <%= render 'shared/response_form', f: f %>
    <%= f.submit "Reply", class: "btn btn-large btn-primary" %>
<% end %>

The above form for replies works fine and gets no errors, the below form for comments gets an error:

undefined method `reply_comments_path’

<%= form_for([@reply, @comment]) do |f| %>
    <%= render 'shared/response_form', f: f %>
    <%= f.submit "Comment", class: "btn btn-large btn-primary" %>
<% end %>

Here is my conversations controller for show, this is where I think the problem is:

  def show
    @conversation = Conversation.find(params[:id])
    @replies = @conversation.replies
    @reply = current_user.replies.build
    #If I change the above line to @conversations.replies.build 
    #it breaks the ability to show replies above the form.

    @comments = @reply.comments
    @comment = @reply.comments.build    
  end

However, someone else suggested doing this:

<%= form_for([@conversation, @reply, @comment]) do |f| %>
    <%= render 'shared/response_form', f: f %>
    <%= f.submit "Comment", class: "btn btn-large btn-primary" %>
<% end %>

But it only ended up with a routing error:

No route matches {:controller=>"comments", :format=>nil, :conversation_id=>#<Conversation id: 3, content: "Goes here.", user_id: 1, created_at: "2012-12-10 21:20:01", updated_at: "2012-12-10 21:20:01", subject: "Another conversation">, :reply_id=>#<Reply id: nil, content: nil, user_id: 1, created_at: nil, updated_at: nil, conversation_id: nil>}

I always get this undefined method path error when I try making new forms and I always manage to forget what I did wrong. The answer never seems to be the routes.

EDIT:

Under the create section in the controller I have:

@replies = @conversation.replies
@reply = current_user.replies.build
#If I change the above line to @conversations.replies.build 
#it breaks the ability to show replies above the form.

I have no idea why @reply = @conversation.replies.build breaks the ability to show the existing replies. I get an error saying it can’t convert nil to a number, and can’t see the reply.created_at or reply.content. Whatever is causing that may be a clue as to why I’m having this problem. However, in the replies controller I AM using

@reply = conversation.replies.build(content: params[:reply][:content], user_id: current_user.id)

EDIT:

Just to add, Stackoverflow does something very similar to what I’m trying to achieve here, except that you can comment on the questions as well as the answers.

  • 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-06-15T17:30:51+00:00Added an answer on June 15, 2026 at 5:30 pm

    Look at the end of your error:

    ... :reply_id=>#<Reply id: nil, content: nil, user_id: 1, created_at: nil, updated_at: nil, conversation_id: nil>}
    

    You can’t create a form for @comment if @reply is not saved. You need to persist @reply before create a @comment to it.

    If you haven’t validates on Reply model try this simple test on show action:

    # @reply = current_user.replies.build
    @reply = current_user.replies.create
    

    See comments for answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm experimenting with Spring Mobile but I can't seem to get the basic example
I am currently experimenting with using nested select statements but my subqueries are generating
I'm experimenting with some multithreading constructions, but somehow it seems that multithreading is not
I'm experimenting with a design. It seems I can't get my CSS right. I
I have been experimenting with using Spring 3.1's bean definition profiles and nested beans.
Experimenting with existential types. Seems to be a great way to get some type
After experimenting with composite operations and drawing images on the canvas I'm now trying
I've been experimenting with mremap(). I'd like to be able to move virtual memory
I've just begun experimenting with nested masters in MVC2. I'm not quite sure why
I'm experimenting with ElasticSearch. I'm having problems with querying nested objects. My mapping: curl

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.