Closed fabianoalmeida closed 11 years ago
I created this issue after suggested by @seixasfelipe here on #16.
'customer' have zero or one 'address', which attribute active_record has to fulfill this requirement?
As address
model is unplugged we can create a partial form with all address
fields and add it on the customer
partial form. For example:
# app/views/customers/_form.html.erb
<%= simple_form_for( @customer ) do |f| %>
<%= f.simple_fields_for :address do |a| %>
<%= render 'address_fields', f: a %>
<% end %>
<%= f.button :submit, :class => 'large primary' %>
<% end %>
In this example the partial form of address
is address_fields
and I'm telling to simple_form
that exists a model (f.simple_fields_for
) inside the customer
called address
that I want to fill using this current form.
So using this solution we can guarantee that a customer
have none, because all address
fields isn't required, or one address
. :wink: In this case, rails will create a new register of address
with empty values if the fields were not filled.
Is it more clear now? :neutral_face:
Nice! Yeah it's clear! Thanks!
Great! What do you think about my ideas to address
model? Can I go ahead with it? Can I create State and Country models? I need a simple feedback to start with this.
Yeah go for it
@seixasfelipe ??
Go Go Go! =)
On Thu, Apr 11, 2013 at 7:34 PM, Rodrigo Fraga notifications@github.comwrote:
@seixasfelipe https://github.com/seixasfelipe ??
— Reply to this email directly or view it on GitHubhttps://github.com/seixasfelipe/cleaners-panamby/issues/37#issuecomment-16268219 .
This model could be an unplugged model and all the other models that belongs to the
address
model will create a foreign key to this model. Fo example, I'm acustomer
and I have anaddress
.So, it's necessary update the
customer
table with a foreign key toaddress
tableAnd in the
customer
model define the relationship between these models. A little ruby code to demonstrate my idea:And here is an example of the
address
model:None attribute will be mandatory on
address
model. If thecustomer
inform his address we will fill all the fields and persist them in database.What do you think?