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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:40:06+00:00 2026-05-13T23:40:06+00:00

I have the following one to many associations. Document has many Sections and Section

  • 0

I have the following one to many associations. Document has many Sections and Section has many Items.

class Document < ActiveRecord::Base
  has_many :document_sections, :dependent => :destroy, :autosave => true
  has_many :document_items, :through => :document_sections
end

class DocumentSection < ActiveRecord::Base
  belongs_to :document
  has_many :document_items, :dependent => :destroy, :autosave => true
end

class DocumentItem < ActiveRecord::Base
  belongs_to :document_section
end

And the ‘edit’ action as follows :-

def edit
  @document = Document.find(params[:id])
end

Here is the edit.html.erb

<h1>Edit!</h1>

<% form_for(@document) do |f| %>
<%= f.error_messages %>

<p>
 <p> Header Comment <p/><br />
 <%= f.text_field :comment %>      
 <%= f.hidden_field :uid %>
</p>

<% @document.document_sections.each do |section| %>
 <% f.fields_for :section, :index => section.id  do |s| %>
  <p>
   <%= s.hidden_field :seqnum, options = {:value => section.seqnum} %>  
  </p>

  <% section.document_items.each do |item| %>
   <% s.fields_for :item, :index => item.id do |i| %>
      <p>
       <%= i.text_area :comments, options = {:value => item.comments} %> 
      </p>
   <% end %>
  <% end %>

 <% end %>
<% end %>
<p>
 <%= f.submit "Submit Comments" %>
</p>

<% end %>

I have to specify the options hash with the value attribute set, for eg:

options = {:value => item.comments} 

in order to show the item comments when I click the ‘edit’ link to modify the item comments. Shouldn’t they be loaded by default, which seems to be the case for header comments.

Thanks for replying. Yes, i want to render the text area with the item.comments value from the database. The below code I had, does not load the comments.

<% s.fields_for :item, :index => item.id do |i| %>
 <p>
  <%= i.text_area :comments %> 
 </p>
<% end %>

can you explain me why

<%= text_area(:item, :comments) %> 

works but

<%= i.text_area :comments %> 

does not. Thanks much.

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

    It seems your understanding of options is not correct. Here is what it is:

    Additional options on the input tag can be passed as a hash with options

    Which means that options sets attributes for the HTML tag.

    You did not specify what exactly you want to do in the question, but I assume you want to render textarea tag with item.comments as a value. If so then you can use the 2nd parameter method (see the docs) and try this:

    text_area(:item, :comments, :size => "20x30")
    # => <textarea cols="20" rows="30" id="item_comments" name="item[comments]">
    #      #{@item.comments}
    #    </textarea>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I have database with the following associations: One Client to Many Intakes One
I have the following snippet in one of my html pages : <div class=inputboximage>
Say I have the following code: function One() {} One.prototype.x = undefined; function Two()
We have similar code to the following in one of our projects. Can anyone
I have the following command which deletes files that are one day old and
I have the following template <h2>one</h2> <xsl:apply-templates select=one/> <h2>two</h2> <xsl:apply-templates select=two/> <h2>three</h2> <xsl:apply-templates select=three/>
I have the following 3 rails classes, which are all stored in one table,
At one of our client's site we have the following topology of BizTalk 2006
If I have a comma separated file like the following: foo,bar,n ,a,bc,d one,two,three ,a,bc,d
Can anyone help? I have the following structure using associations, and as you can

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.