# Display collection stuff

**URL:** <https://www.ruby-forum.com/t/display-collection-stuff/196489>\
**Category:** Rails\
**Created:** [October 17, 2007, 12:50am UTC](https://www.ruby-forum.com/t/display-collection-stuff/196489 "2007-10-17T00:50:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nuby2ruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/54ee81/32.png) [@nuby2ruby](https://www.ruby-forum.com/u/nuby2ruby)\
**Post date:** [October 17, 2007, 12:50am UTC](https://www.ruby-forum.com/t/display-collection-stuff/196489/1 "2007-10-17T00:50:51Z")

</div>

Hi, I am a bit confused on exactly how this works out.  
I have ObjectA which has\_many :things and Thing belongs\_to :object\_a

So, what I want to do is display all the things that ObjectA has in a  
text\_area. When I have

\<%= f.text\_area(“things”) %\>

I get a text\_area with

#Thing:0x460efb0#Thing:0x460ef38

I want to display thing.name, but I’m stuck at this point.

Any help would be great, thanks.

~Jeremy

---

<div class="post-metadata">

**Author:** ![nuby2ruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/54ee81/32.png) [@nuby2ruby](https://www.ruby-forum.com/u/nuby2ruby)\
**Post date:** [October 17, 2007, 1:36am UTC](https://www.ruby-forum.com/t/display-collection-stuff/196489/2 "2007-10-17T01:36:38Z")

</div>

Your code makes Rails do object\_a.things and put the result in the  
text area. when outputting an object like a string, ruby prints out  
what you see, class name and the (internal ruby) object’s id: #\<Thing:  
0x460efb0\>

you will have to do something like this:  
\<%= text\_area\_tag “things”, @object\_a.things.map{ |t| t.name }.join("  
") %\>

then, when submitting the form, the content will be in params[:things]  
if however you want it in params[:object\_a][:things], change it like  
this:

\<%= text\_area\_tag “object\_a[things]”, @object\_a.things.map{ |t|  
t.name }.join(" ") %\>

be aware that this could lead to problems when doing mass assignment:  
@object\_@ =Object\_a.new(params[:object]  
=\> “things” is no attribute of object\_a (it’s only an associtiaon),  
and produce an error.  
you can however catch this with a virtual attribute…

On 17 Okt., 00:50, Jeremy W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![nuby2ruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/54ee81/32.png) [@nuby2ruby](https://www.ruby-forum.com/u/nuby2ruby)\
**Post date:** [October 17, 2007, 8:06pm UTC](https://www.ruby-forum.com/t/display-collection-stuff/196489/3 "2007-10-17T20:06:40Z")

</div>

Thorsten wrote:

> you will have to do something like this:  
> \<%= text\_area\_tag “things”, @object\_a.things.map{ |t| t.name }.join("  
> ") %\>
> 
> then, when submitting the form, the content will be in params[:things]  
> if however you want it in params[:object\_a][:things], change it like  
> this:
> 
> \<%= text\_area\_tag “object\_a[things]”, @object\_a.things.map{ |t|  
> t.name }.join(" ") %\>

Thanks, it didn’t work, but I did figure out what I needed.

\<%= f.text\_area “things”, :value =\> @object\_a.things.map{ |t| t.name  
}.join(" ") %\>

~Jeremy
