On Thu, Jul 24, 2008 at 8:09 AM, Adam
<anlauf.adam-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> I got a model relationships
> Country <- (hm) city <- (hm) Address
>
> The table city has two fields (both required)
> integer :country_id
> string :name
>
> When creating a city the user can type a country in a country field
> <%form_for @city do |f| %>
> <%= f.label :country %>
> <%= f.text_field :country %>
> <%= f.label :country %>
> <%= f.text_field :country %>
> <%end%>
>
> Before creating i would like to find a country by its name, if the
> name wouldn''t exist then a new country would be created and
it''s `id`
> (the new created ones) would be placed in country_id (so
> self.country_id = id) field of the new city.
> Then if it validated a new city would be saved to database.
>
> I was trying to do this in the model but couldn''t succeed.
> My general idea was to do it with a callback like before_create, but
> it failed.
>
> Any ideas on this one?
>
Did you try before_validation_on_create?
>
>
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---