the text_field tag expects an object to exist so that it can use the
specified attribute as the value for the field
so say i have the following in my ''new.rhtml'' view:
text_field :user, :name
i might have in my ''new'' action
@user = User.new(:name => "Billy")
when the view renders, the field will contain the value
''Billy''
keeping that in mind, say i submit my form to a ''create''
action
def create
@user = User.new(params[:user])
if @user.save
redirect_to :action => :list and return
end
render :action => ''new'' and return
end
what happens here is that if there was a missing field in my form for
whatever reason, i want to render the ''new'' template and since
i
already instantiated @user, it''s attributes will populate the form
fields.
in your case, you would need a Billing object created to populate your
fields, and it doesn''t look like you have that.
On 2/7/07, The Barge
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
> I''m using the text_field tag to output my form inputs. In the
past this
> works perfectly when using model validation. Here''s my problem..
a
> 3-step checkout process so I''m collecting form data as I go along.
So
> after step 1 (billing address), I''m posting the form with a
different
> hidden "step" input to the same action.
>
> So the "checkout" action handles all three steps similar to the
> following...
>
> def checkout
> if ! @params[:step]
> render :action => "checkout_billing"
> elsif @params[:step] == "shipping"
> errors = valid_billing # check the input for required fields
> if errors.size > 0
> render :action => "checkout_billing"
> else
> render :action => "checkout_shipping"
> end
> elsif @params[:step] == "payment"
> ...snip...
> end
> end
>
> So I''m on the checkout_billing page, I enter my first name and
nothing
> else. It will render checkout_billing again since there are more
> required fields. But the text_field for billing[first_name] isn''t
> autopopulated with my first name like the text_field helper usually
> does.
>
> Any ideas why?
>
> --
> 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
-~----------~----~----~----~------~----~------~--~---