Forum: Ruby on Rails How to pre-populate Edit form in rails?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
548240c1431285c235ecf711293a7311?d=identicon&s=25 Yash (Guest)
on 2006-02-25 12:18
In our rails application, there is a model called Essay and another
called Tag. Essay 'has_and_belongs_to_many' tags. When a user CREATEs an
essay, he gives the text in a text field which corresponds to a database
column in the essays table. The _form.rhtml also provides a text area
that lets the user tag the essay with keywords. The text area does not
correspond directly to any single column in the essays table. The text
is parsed and used to populate the tags table and set relations between
the essay and the tags.

This works when I create a new essay. When I try to EDIT and essay, I
would like to see the previously entered tags. This means the Tags text
area should be pre-populated. How do I do this?

Thanks,
Yash
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (Guest)
on 2006-02-25 13:33
(Received via mailing list)
Yash wrote:
> would like to see the previously entered tags. This means the Tags text
> area should be pre-populated. How do I do this?
>

<%= text_field_tag 'essay_tags',
	@essay.tags.collect{|t| t.name}.join(',') %>

That's assuming that you're splitting your tags on commas, of course...
This topic is locked and can not be replied to.