Sorry for the garbled code. Here's a pastie link instead:

http://www.pastie.org/801584

On Jan 30, 4:58 pm, Erol Fornoles <erol.forno...@gmail.com> wrote:
> You might want to check out:
>
> http://github.com/Erol/nested_reference
>
> Assuming your models were Person and ZipCode, and ZipCode has a field
> called 'code':
>
> class Person
>   belongs_to :zip_code
>   validates_presence_of :zip_code, :message => 'Zip Code can't be
> empty or was not found in the list of valid codes.'
>
> accepts_nested_reference_and_attributes_for :zip_code, :code, :required
> => true
> end
>
> View:
>
> form_for @person do |p|
>   p.text_field :name
>   p.fields_for :zip_code |zc|
>     zc.text_field :code
>   end
> end
>
> Controller:
>
> person.update_attributes(:person) # Nothing special needs to be done.
> person.zip_code_id will be set depending on the zip code the user
> filled in.
>
> You can add auto-completion in your view. I'd recommend jQuery
> Autocomplete.
>
> Hope this helps,
>
> On Jan 29, 8:16 pm, eugenio <eugenio.mode...@gmail.com> wrote:
>
> > one of my model belongs_to another (zip codes).
> > i would like to let the user insert the zip code in a text field
> > instead of the select menu generated by the collection_select.
> > No new zip code should be created and the code should be validated (it
> > should be in the list of valid code).
> > How can this be achieved?

-- 
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-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to