Forum: Ruby on Rails Automatically Filling in form field tags

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.
54a6fc785e9fcf73ead8e387432b32f5?d=identicon&s=25 Dan Harper (Guest)
on 2006-03-25 05:18
(Received via mailing list)
I have a form which is predominantly a customer form (first name, last
name, etc), if there is a form error and I render to the form from the
controller the customer details are filled in correctly.

The question I have is, I have some fields which are _tag fields not
related to the customer model, how do I get them populated when I render
back to the form on error?

Cheers,
Dan
8a00145d61d84b58c4688cdc50bac48f?d=identicon&s=25 Wiebe Cazemier (halfgaar)
on 2006-03-25 13:44
Dan Harper wrote:
> I have a form which is predominantly a customer form (first name, last
> name, etc), if there is a form error and I render to the form from the
> controller the customer details are filled in correctly.
>
> The question I have is, I have some fields which are _tag fields not
> related to the customer model, how do I get them populated when I render
> back to the form on error?

I think you're going to have to set the value you want in the controller
method, and use that value as "value" of the _tag.

Like so:

text_field_tag("name_of_field", @contents_variable).

And then in your controller, in the update method for example:

@object.attributes = stuff

if object.save
 [stuff]
 [probably redirect_to :action => list]
else
 @contents_variable = "stuff you want to re appear on error"
 render(:action => "edit")
end

Or at least, something to this effect. The important part is setting the
@contents_variable. You can also do this anyway, without an if
statement, when using validations for example.
This topic is locked and can not be replied to.