Automatically Filling in form field tags

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

Dan H. 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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs