Re: Form responders

Duane Johnson
2005-10-05T06:45:21Z

If I understand the problem correctly, you can use an
''ostruct'' to
accomplish what you''re looking for.

irb(main):001:0> require ''ostruct''
=> true
irb(main):002:0> user = OpenStruct.new(:first_name =>
"Duane", :last_name => "Johnson")
=> <OpenStruct first_name="Duane"
last_name="Johnson">
irb(main):003:0> user.first_name
=> "Duane"

You can set, for example, a @user instance variable and let it act
like the handy little accessor object that it is.

Duane Johnson
(canadaduane)

On Oct 4, 2005, at 6:48 PM, Julian ''Julik'' Tarkhanov wrote:

> Odd question but I think it slips through without me noticing a
> viable response.
>
> How can I set up some meaningful ActiveRecord stub so that I can
> make a "form responder" - or even better, make my controller be
> this responder. What I would love to have is form values persisting
> through reloads without loading them manually into the view.
> Helpers nicely address this, but there the params are stored inside
> a model objects. Form helpers, as I take it, (by the way of the
> dirtiest hack on earth :-) can only address controller instance
> variables. So the question is - if I want to merely persist some
> values through reloads and use the form helpers (they are times
> more convenient than usual forms) the only way I can go about it is
> build a custom container class that will mimick AR::Base?
>
> Same about a login field. How do I somply persist the password and
> login field input if the login fails for some reason?
>
> Take for instance an "incremental search" form where you can
select
> stuff from the DB bu using a set of conditions - I would like the
> menu positions and other inputs to persist between reload  (and use
> the helpers).On a project I just finished I built a Finder object
> that worked kind of like AR, but maybe there is a nicer way?
>
> Or, maybe there gotta be a take 2 like this:
>
> 1. load the params into the flash
> 2. on redirect make these params available as an instance variable
> so that helpers can get to it
> 3. make this instance variable have a class which does not raise
> anything on method_missing, so that if form helpers
> get to it and it is empty they just show nil values.
>
> Ay advice? Right now all of the forms which are decoupled from AR
> in my app are sort of deprived of all the Rails magic you can put
> to some good use.
>
> --
> Julian "Julik" Tarkhanov
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>