Ok, I have rewritten my form code to follow this but its not solving my core
problem.
Maybe its just me but rails seems a bit of a mess when it comes to form
code.
I have one app that runs against 1.1.6. I have a form with the following
code:
<%= form.file_field("jar_file") %>
In my model I have:
def jar_file=(jar_field)
#stuff
end
This works fine. Howevern in a new app running on rails 1.2.1 I have the
following code:
<%= f.password_field("password") %></p>
with this in my model:
def password=(pass)
#stuff
end
This fails with the error:
undefined method `password'' for #<User:0x377e560>
Is there a ''correct'' approach for this. Rails seems to allow
me to set
up forms in
a number of ways but I can find nothing that says this is the right
way to do it.
Keith
On 2/13/07, s.ross <cwdinfo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
>
> Both take blocks now. When using form_for, supply the block with a
> symbol denoting the corresponding object, then you don''t have to
> restate it everyplace:
>
> <% form_for :people do |f| %>
> <p>
> name
> <%= f.text_field :name %>
> </p>
> <p>
> address
> <%= f.text_field :address %>
> </p>
> <% end %>
>
> In particular, this is great when there are multiple forms on the
> same page. You specify:
>
> <% form_for :people %>
> # stuff here
> <% end %>
>
> <% form_for :addresses %>
> #stuff here
> <% end %>
>
> Does this help?
>
> On Feb 12, 2007, at 3:33 PM, Keith Davey wrote:
>
> > Can someone explain what is the correct way with Rails 1.2 to use a
> > form to create an object.
> >
> > I know start_form_tag is changed to form_tag but what about form_for?
> >
> > I am trying to map a field on to field in the object which is
> > created by a method call,
> > so something like this def password=(pass) and so on. However, this
> > seems to work fine for me
> > in some cases but not in others.
> >
> > Thanks,
> >
> > Keith
> >
> > >
>
>
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---