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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:14:19+00:00 2026-05-11T17:14:19+00:00

Has anyone run into this problem? I have a collection of comments that I

  • 0

Has anyone run into this problem?

I have a collection of comments that I loop through in the view as normal:

<% for comment in @post.comments %>
  <%= comment.body %>
<% end %>

But I also have a form to add a comment, but it seems that if I use @post.comments.build instead of Comment.new in the controller, that it created a blank instance of a ‘comment’ in the loop.

I would prefer to use .build not .new
Has anyone encountered this? Is there a hack?

Thanks

  • 1 1 Answer
  • 3 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-11T17:14:19+00:00Added an answer on May 11, 2026 at 5:14 pm

    Funny you mention, I encountered this a few days ago.

    I ended up going with Model.new but you could also try reloading the association after you call build.

    @post.comments(true) will reload it. (You may also write @post.comments(:force_reload) for readability.)

    An alternative to reloading might be calling the all named scope for the association, so @post.comments.all.

    I think both will issue a new query anyway, but maybe they’ll hit query cache.

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

Sidebar

Related Questions

Has anyone run into this problem... In my layout.phtml I have: <head> <?= $this->headTitle('Control
Has anyone ever run into this issue before? Sometimes the string displays, sometimes half
I am curious to see if anyone else has run into this same issue...
has anyone an idea why I have the following problem with passing locals to
I have run into a quirk in MYSQL that is proving to be very
Has anyone mapped out a way to create a hot-key for 'Run As' in
Has anyone successfully tried minifying AND concatenating all the jqGrid locale files so that
Has anyone met this error? Right now i am trying to do switch from
Has anyone else come across this at all? I used to be able to
I have a simple Java app that inserts records into a table A, linking

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.