Active Admin NoMethodError错误

我在我的rails应用程序上设置了活动管理员。 我运行生成器来创建用户资源但是当我点击管理仪表板上的用户链接时,我得到:

NoMethodError in Admin/users#index Showing /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeadmin-0.4.4/app/views/active_admin/resource/index.html.arb where line #1 raised: undefined method `city_id_contains' for # Extracted source (around line #1): 1: render renderer_for(:index) 

我不知道是什么产生了这个或错误来自何处..任何想法? 谢谢! (如果您需要查看任何其他文件,请告诉我)

楷模:

 user.rb class User < ActiveRecord::Base rolify devise :database_authenticatable, :registerable, :confirmable, :recoverable, :rememberable, :trackable, :validatable attr_accessible :province_id, :city_id belongs_to :province belongs_to :city 

province.rb

  class Province < ActiveRecord::Base has_many :cities has_many :users end 

city.rb

 class City < ActiveRecord::Base belongs_to :province has_many :users end 

schema.rb

  create_table "users", :force => true do |t| t.string "email", :default => "", :null => false t.string "encrypted_password", :default => "", :null => false t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" t.integer "sign_in_count", :default => 0 t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" t.string "current_sign_in_ip" t.string "last_sign_in_ip" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false t.string "name" t.date "date_of_birth" t.string "address" t.string "gender" t.integer "zipcode" t.string "city" t.string "status" t.string "confirmation_token" t.datetime "confirmed_at" t.datetime "confirmation_sent_at" t.string "unconfirmed_email" t.integer "province_id" t.integer "city_id" end create_table "provinces", :force => true do |t| t.string "name" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false end create_table "cities", :force => true do |t| t.string "name" t.integer "province_id" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false end 

这个问题帮助我解决了我的问题。 我不得不阅读评论以找出如何解决它,所以我在这里提供答案:

如果您的模型包含belongs_to关系,则如果您的列名与您的属于外键ID列名相匹配,则Active Admin将不会喜欢它。

例如,在这种情况下,您的外键是“city_id”,但您还有一个名为“city”的列。 Active Admin不喜欢这个。 同样,开始使用该列确实没有意义。 因为你将通过这种关系进入城市。

要解决此问题,您应该创建一个删除城市列的迁移。

 class RemoveCityFromUser < ActiveRecord::Migration def up remove_column :users, :city end end