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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:01:43+00:00 2026-06-01T14:01:43+00:00

I have a Page with many Comments. Many users can access this page and

  • 0

I have a Page with many Comments. Many users can access this page and submit comments. I view the comments on another Page that is private.

models/page.rb

class Page < ActiveRecord::Base
  has_many :comments, :dependent => :destroy 
  accepts_nested_attributes_for :comments, :allow_destroy => true
end

models/comment.rb

class Comment < ActiveRecord::Base
  belongs_to :page
  belongs_to :user
end

views/pages/show.html.erb relevant section

<%= form_for @page, :remote => true do |f| %>
    <% f.fields_for :comments do |builder| %>
   <%= builder.text_area :content, :rows => 1 %>
   <%= builder.submit "Submit" %>
    <% end %>
<% end %>

controllers/pages_controller.rb

def show
  @page = Page.find(params[:id])
end

def update
  @page = Page.find(params[:id])
  @page.comments.build
  @page.update_attributes(params[:page])
end

The issue here is that I do not want to have the user see multiple fields for comments. Yet, if I do <% f.fields_for :comment do |builder| %> then it throws an error because it doesn’t know what one comment is, and only wants to deal with multiple.

Essentially, the user should be able to submit a single comment on a page, which has many comments, and have that automatically associated with the page. As a secondary thing, I need to have the user’s id (accessible through current_user.id via Devise) associated with the comment.

  • 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-01T14:01:49+00:00Added an answer on June 1, 2026 at 2:01 pm
    <% f.fields_for :comments, f.object.comments.build do |fc| %>
      <!-- rest of form -->
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this web page where users can add smilies to their comments. And
I have a Page, this Page has many, one or no comments. At one
I have a page upon which a user can choose up to many different
I have a ASP.NET web page that contains many textboxes. Each textbox has a
I have a Rails application (Rails 3.0.10) where users can have many articles, and
I have tables of venues, reviews and comments where a venue can have many
I'm pretty sure that many people have thought of this, but for some reason
I have some JavaScript that can appear on many different pages. Sometimes those pages
I have a page with many forms in panels and usercontrols, and a requiredfield
I have a page with many forms on it. could be 1..200. None of

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.