Ciao a tutti,
Sto usando rails 3.2 ed ho un grossissimo problema con l’errore
riportato nel subject e non ho
la più pallida idea di come risolverlo.
Riassumendo sto cercando di utilizzare uno stesso form per inserire i
dat in due modelli diversi fra cui c’è una relazione has_one.
I due model sono:
class Ad < ActiveRecord::Base
default_scope order(‘created_at DESC’)
belongs_to :user
has_one :location
accepts_nasted_attributes_for :location
validates :title, :description, :tags, :presence => true
…
end
class Location < ActiveRecord::Base
belongs_to :user
attr_accessible :address_1,
:address_2,
:city,
:state_province_region,
:zip_postal_code,
:country,
:position,
:user_id
validates :address_1, :city, :state_province_region, :zip_postal_code,
:country, :user_id, :presence => true
validates :zip_postal_code, :numericality => true
…
end
e questo è il form (completo):
<%= form_for(@ad) do |f| %>
<% if @ad.errors.any? %>
<%= pluralize(@ad.errors.count, “error”) %> prohibited this ad
from being saved:
<ul>
<% @ad.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<%= f.text_field :title %>
<%= f.text_area :description %>
<%= f.text_field :tags %>
<div class="field">
<div><%= fl.label :address_1 %><br />
<%= fl.text_field :address_1 %>
</div>
<div class="field">
<div><%= fl.label :address_2 %><br />
<%= fl.text_field :address_2 %>
</div>
<div class="field">
<div><%= fl.label :city %><br />
<%= fl.text_field :city %>
</div>
<div class="field">
<div><%= fl.label :state_province_region %><br />
<%= fl.text_field :state_province_region %>
</div>
<div class="field">
<div><%= fl.label :zip_postal_code %><br />
<%= fl.text_field :zip_postal_code %>
</div>
<div class="field">
<div><%= fl.label :country %><br />
<%= fl.country_select(:country, [ "France", "Germany", "Italy",
“United Kingdom”, “United States”, “Spain”]) %>
<% end %>
Grazie a tutti per l’aiuto in anticipo