2017-01-23 5 views
0

Ich habe einen Controller für Property und andere für Land ein Objekt verfügt über ein Landsimple_forms mit zwei Klassen

My Property Modell

class Property < ApplicationRecord 

    acts_as_paranoid 

    has_one :country, class_name: Country 
    belongs_to :company 

    accepts_nested_attributes_for :country 

    validates :name, presence: true 
    validates :address, presence: true 

Mein Land Modell

class Country < ApplicationRecord 

    acts_as_paranoid 

    belongs_to :property 

    validates :name, presence: true 
    validates :isoalpha2, presence: true 
    validates :isolapha3, presence: true 
Und

, wenn ich will eine Eigenschaft mit meiner Sicht (new.html.erb)

<%= simple_form_for [@property, @country], url: property_new_path do |f| %> 
    <% if @property.errors.any? %> 

      <%= pluralize(@property.errors.count, "error") %> prohibited 
      this property from being saved: 

      <% @property.errors.full_messages.each do |msg| %> 
       <li><%= msg %></li> 
      <% end %> 

    <% end %> 
      <%= f.input :name %> 
      <%= f.input :description %> 
      <%= f.input :address %> 

      <%= f.submit %> 

ich die folgende Fehlermeldung hinzuzufügen:

nicht definierte Methode `Beschreibung‘ für # < Land: 0x8de0b20 >

ich weiß nicht, warum statt Eigentum der Land Klasse nimmt, weil Beschreibung Teil des Property-Controller

Dank ist

Antwort

0

Das sollte wie sein

<%= simple_form_for [ @country, @property] do |f| %> 

und Routen in verschachtelten Form

resources :countries do 
    resources :properties, except: [:index] 
end 

Hoffnung sollte dies für Sie arbeiten

+0

nicht funktioniert, warum Länder? und warum haben Sie die Reihenfolge zuerst <@> Land und später <@> Eigenschaft geändert? –

+0

Erste Kasse http://guides.rubyonrails.org/routing.html#nested-resources –