0
我有一個控制器,用於物業和另一個用於國家一個酒店有一個國家simple_forms有兩類
我的房屋模型
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
我的國家模式
class Country < ApplicationRecord
acts_as_paranoid
belongs_to :property
validates :name, presence: true
validates :isoalpha2, presence: true
validates :isolapha3, presence: true
當我想添加一個屬性與我的觀點(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 %>
我收到以下錯誤:
未定義的方法'說明」爲#< 國家:0x8de0b20 >
我不知道爲什麼,走的是國類而不是屬性,因爲描述的是物業控制器的一部分
感謝
沒有工作,爲什麼國家?你爲什麼要先改變<@>國家和後來的<@>財產? –
首次結帳http://guides.rubyonrails.org/routing.html#nested-resources –