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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:59:11+00:00 2026-05-17T23:59:11+00:00

I have a model that I want to be commentable. I am having difficulty

  • 0

I have a model that I want to be commentable. I am having difficulty creating a form on my model’s ‘show’ view that will allow comments to be created. I am not finding any good or useful examples. Can anyone point me to or show me an example of how to do this?

Example:

A simple blog application. I have a model called Post. It is commentable. So on the ‘show’ view I want to show a Post and, at the bottom, have the fields that, when completed and submitted, create a new comment associated with the post and put it in the database.

Sounds straightforward and I have it working so I can display comments that I have seeded. I just can’t get a form to work to put new ones in. Any help is appreciated.

  • 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-17T23:59:11+00:00Added an answer on May 17, 2026 at 11:59 pm

    This is very, very basic stuff and you clearly need some better structure and approach to your learning. Buying a book, such as Agile Web Development with Rails, is the only real way to learn, otherwise you’ll wander from problem to problem without ever actually learning anything well.

    Say you have a post that you want to comment.

    #routes.rb
    map.resources :posts do |post|
      post.resources :comments
    end
    
    #post_controller.rb
    def show
      @post.find params[:id]
      @comment = @post.comments.new
    end
    
    #posts/show.html.erb
    <%- form_for [@post, @comment] do |f|-%>
      <%= f.text_area :body -%>
      <%= f.submit -%>
    <%- end -%>
    
    #comments_controller
    def create
      @post = @post.find params[:post_id]
      @comment = @post.comments.new params[:comment]
      if @comment.save
        redirect_to @post
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 3D CAD model that I want to show on a web page.
I have a rails model that validates uniqueness of 2 form values. If these
I have a scenario where I have a model that I want to populate
I have a GeoDjango model object that I want't to serialize to json. I
I have an object model that I want to store using an embedded database.
I have a model in django that I want to update only, that is,
I have a Model with data that I want to use to populate a
I have a model that has ratings in it for an post. I want
Say have a linear model LM that I want a qq plot of the
I have a model class that has an AreDuesPaid property that I want only

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.