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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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 Woertink
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> 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
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---