我使用rails 4.01和activeadmin 1.0。我的模特是:
class City < ActiveRecord::Base
extend FriendlyId
friendly_id :name, use: :slugged
translates :name, :city_h1, :city_h2, :city_h3, :city_description
belongs_to :region
belongs_to :country
has_many :city_translations
accepts_nested_attributes_for :city_translations
end
class CityTranslation < ActiveRecord::Base
extend FriendlyId
belongs_to :city
validates_uniqueness_of :locale, :scope => :city_id
end
管理员/ cities.rb
ActiveAdmin.register City do
permit_params :name, :city_h1, :city_h2, :city_h3, :city_description, :region_id, :country_id, :city_translations_attributes,
city_translations_attributes: [:id, :city_h1, :city_h2, :city_h3, :city_description, :city_id, :locale, :_destroy, :_create, :_update,:_update]
form :html => { :enctype => "multipart/form-data" } do |f|
f.inputs "Details" do
f.input :region, :include_blank => false
f.input :country, :include_blank => false
end
f.inputs "Vertalingen" do
f.has_many :city_translations do |g|
g.inputs "taal" do
g.input :locale, :as => :radio, :collection => ADDITIONAL_LOCALES, :label => "Taal"
end
g.input :name
g.input :city_h3
g.input :city_h1
g.input :city_h2
g.input :city_h3
g.input :city_description
end
end
f.actions
end
end
我收到错误
CityTranslation的未定义方法`'
迹:
activemodel (4.0.3) lib/active_model/attribute_methods.rb:439:in `method_missing'
activerecord (4.0.3) lib/active_record/attribute_methods.rb:155:in `method_missing'
friendly_id (5.0.4) lib/friendly_id/base.rb:242:in `friendly_id'
activemodel (4.0.3) lib/active_model/validator.rb:151:in `block in validate'
activemodel (4.0.3) lib/active_model/validator.rb:150:in `each'
activemodel (4.0.3) lib/active_model/validator.rb:150:in `validate'
activesupport (4.0.3) lib/active_support/callbacks.rb:283:in `_callback_before_1715'
activesupport (4.0.3) lib/active_support/callbacks.rb:377:in `_run__2897005105520448373__validate__callbacks'
我试图解决这个问题2天,但我无法弄清楚我做错了什么。
thanks..remco