[英]Active Admin NoMethodError Error
Im setting up active admin on my rails app. 我在我的Rails应用程序上设置了活动管理员。 I ran the generator to create the user resource but when i click on the users link on the admin dashboard i get:
我运行了生成器来创建用户资源,但是当我单击管理仪表板上的用户链接时,我得到:
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 #<MetaSearch::Searches::User:0x007fde92d69840>
Extracted source (around line #1):
1: render renderer_for(:index)
I have no clue what is generating this or where the error is coming from.. Any ideas? 我不知道是什么原因导致的,或者错误是从哪里来的。 Thanks!
谢谢! (please let me know if you need to see any other files)
(请让我知道是否需要查看其他文件)
Models: 楷模:
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 province.rb
class Province < ActiveRecord::Base
has_many :cities
has_many :users
end
city.rb city.rb
class City < ActiveRecord::Base
belongs_to :province
has_many :users
end
schema.rb 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
This question helped me solve my problem. 这个问题帮助我解决了我的问题。 I had to read the comments to figure out how to solve it so I am providing the answer here:
我必须阅读注释以找出解决方法,因此在此提供答案:
If you have a model that contains a belongs_to relationship, Active Admin will not like it if you have a column name that matches your belongs to foreign key id column name. 如果您的模型包含一个belongs_to关系,并且您的列名与您属于所属外键ID的列名匹配,则Active Admin将不喜欢它。
For instance in this case your foreign key is 'city_id' but you also have a column named 'city'. 例如,在这种情况下,您的外键是“ city_id”,但是您还有一列名为“ city”。 Active Admin doesn't like this.
Active Admin不喜欢这样。 And likewise it really doesn't make sense to have that column to begin with.
同样,以该列开头确实没有任何意义。 Since you will access the city through the relationship.
因为您将通过关系访问城市。
To fix this you should create a migration that removes the city column. 要解决此问题,您应该创建一个删除城市列的迁移。
class RemoveCityFromUser < ActiveRecord::Migration
def up
remove_column :users, :city
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.