基本多态导轨形式

| 视图(在此需要帮助)还是我需要更改accepts_nested_attributes。我需要一个表格来创建一个属性和相关地址,以City开头。此时,出现以下错误:
unknown attribute: address
。此外,我想在创建后重定向回去;不知道如何使用Inherited_resources做到这一点。非常感谢你。
= form_for Property.new do |f|
  = f.fields_for :address do |builder|
    = builder.label :city
    = builder.text_field :city
  = f.submit

class Property < ActiveRecord::Base
  include ActiveRecord::Transitions
  include ActsAsAsset
  include Amendable
  include Searchable

  acts_as_taggable_on :tags

  has_many :addresses, :as => :addressable
  has_many :escrows
  has_many :events, :as => :entity
  has_many :phone_numbers, :as => :phoneable

  accepts_nested_attributes_for :addresses
  .
  .
  .
end
class Address < ActiveRecord::Base
  belongs_to :addressable, :polymorphic => true
  belongs_to :address_category
  has_many :notes, :as => :notable

  validate :not_blank
  validates :addressable, :presence => true

  private

    def not_blank
      self.errors.add :base, \'cannot be blank\' if
        self.attributes.values.all? {|attr| attr.blank? }
    end
end

class PropertiesController < ApplicationController
  inherit_resources

  before_filter :authenticate_user!

  def index
  end

  def show
  end
end
    
已邀请:
        由于这是一个2关系,因此您需要\'addresses \'而不是\'address \'。 应该是这样的:
= form_for Property.new do |f|
  = f.fields_for :addresses do |builder|
    = builder.label :city
    = builder.text_field :city
  = f.submit
    

要回复问题请先登录注册