Displaying a nested field as a label

There is what I'm doing: I want to display a series of text_area
fields (read only) of which each has a checkbox.

Is this the best way to do it?

<% form_for (@section), :url =>{:action => "save_comments"} do |f| %>
    <% f.fields_for :comments do |a|%>
         <li>
            <%= a.text_area :text, :read_only => 'true' %> <br>
            <%= a.check_box :approval_boolean %> <br>
            <hr>
         </li>
    <% end %>
<% end %>

Is there any other way to display the field "text" other than above?

Thanks!

If it is going to be read-only, why do you need to display it in a
text_area instead of directly on the page?

andrew wrote:

That's my question! How do you do that.

<% a.text %> gives me this error:

NoMethodError in Sections#edit_acknowledgments

Showing app/views/sections/edit_acknowledgments.html.erb where line
#11 raised:

Thanks! -a

<%=h a.text %>

BTW, "a" is not a very helpful name for a block variable (or any
variable for that matter). Assuming you're not paying for your code by
the byte, it would be more legible thus:

  <% f.fields_for :comments do |comment|%>
    ...
    <%=h comment.text %>

YMMV

That's my question! How do you do that.

<% a.text %> gives me this error:

You want just
<%= text %>
or probably
<%= h text %> dependant on where text is coming from

Colin

Ok, I'll clean up the variable names. Thanks! :slight_smile:

However....

<%=h comment.txt %> undefined method `text'
<%= text %> and <%=h text %> give undefined local variable or method
`text'

Neither of those ideas work. :frowning:

Well what *is* your "a/comment" variable? Have you debugged it to see
what's going on in that block? Do you *know* what methods it's got, or
are you assuming there's a "text" method?

You can use <% puts .... %> or <% logger.info .... %> to output
messages to help you diagnose what's going on. Personally, I prefer to
use breakpoint debugging in Netbeans.

does 'puts a.respond_to("text")' display true?
what does 'puts a.inspect' give you?

This is a nested model form using to models: section and comment,
where section has many comments.

"text" is a field for comments
"approval_boolean" is a field for comments

I just want the field value for "text" to show up as a non-form-
element and "approval_boolean" to show as a check box form element.

The code above works, but I can only get the "text" field to show up
as a text_area or text_field form element.

Like I said, if <%= a.text %> worked, I'd be happy... but it gives me
a method error and I'm not sure why.

Ahhhh! a.class = formbuilder. I thought it was a Comments class.
Now I know what to look up.... I guess my question after all is there
any way to "extract" a data value from a field within a formbuilder?
(if I got my terminology right)

Thanks for taking the time to look at this, btw.

-a

a.object.text
(although I'm using Formtastic "SemanticFormBuilder" objects here, so
have fingers crossed the method is the same - dumping "a.methods"
would help you a little if 'object' doesn't work...)

That's exactly what I was looking for!

THANK YOU!

And thanks for the insight.

-a