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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:32:08+00:00 2026-05-24T09:32:08+00:00

This example shows how to create a form for an associated model ‘Comment’, where

  • 0

This example shows how to create a form for an associated model ‘Comment’, where ‘Comment’ belongs_to ‘Post’ and ‘Post has_many ‘Comments’.

http://edgeguides.rubyonrails.org/getting_started.html#generating-a-controller

How might I modify that to display all the comments in the form, and still have it call the CommentsController (versus having the form call the PostsController, as in the example here http://railscasts.com/episodes/17-habtm-checkboxes)?

Thanks

UPDATE:

To ask a different way: Using a Polymorphic Assocation, if Photo and Article each ‘has_many’ Comments, the comment form should call the CommentsController, as shown here http://railscasts.com/episodes/154-polymorphic-association — But what if I’m editing multiple comments in one form for a given Photo. In this case should the form still call the CommentsController or is it better off calling the PhotoController?

  • 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-24T09:32:09+00:00Added an answer on May 24, 2026 at 9:32 am

    Here’s the updated answer:

    I’d still use the CommentsController to do all the updating of comments. Unless you’re editing the post and its comments at the same time. Since you’re editing a post’s comments, what you can do is just POST them to an action in the comments controller. In your view, make a form with a fields_for for each comment.

    Then, they can all post to an update_multiple (or something similarly named) action in the CommentsController. It’s just a matter of accepting the params hash and parsing it properly.

    def update_multiple
      # I'd expect the params hash to look like:
      # {"comments" => {"1" => {"body" => "my body"}, "comment_2" => {"body" => ""}}
      # To keep your controllers thing, stick it into the model!
      if Model.update_multiple params[:comments]
        respond_to do |f|
          #...
        end
      end
    end
    

    In your model (just make it more robust by doing it all in a transaction, so if one fails, then none of them are updated. Well, that’s really up to you):

    def self.update_multiple(hash)
      updated_all = true
      hash.each do |key, value|
        comment = self.find key.to_i
        updated_all = false unless comment.update_attributes(value)
      end
      updated_all
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Click here to see example http://www.messtudios.com/form/ Now, when you click on Create Account -
I'm following this example: http://www.codinghorror.com/blog/2005/12/getting-started-with-indexing-service.html However, the conversion to dataset shows empty columns for
The example on this page only shows Groovy assertions without parentheses. assert a !=
I've watched this video from Google I/O 2009: http://www.youtube.com/watch?v=AgaL6NGpkB8 where Brett shows microblogging example.
How can I create a dynamic form using jQuery. For example if I have
This is probably best shown with an example. I have an enum with attributes:
To show, for example.... USER@SID > I thought this was potentially helpful to a
Given the example below, can someone please show me how this could be called?
This example is from php.net: <?php function Test() { static $a = 0; echo
This example uses a StringWriter to hold the serialized data, then calling ToString() gives

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.