使用gem:rails_admin 出错,无法把admin写进users中
gem 'rails_admin' bundle rails g rails_admin:install rails s
在config/initializers/rails_admin.rb中添加
config.authorize_with do redirect_to main_app.root_path unless current_user.admin == true end
在db/migrate/ DeviseCreateUsers 中添加
t.boolean :amin
然后
rake db:migrate
进入 rails c
u = User.first
没有 admin 的情况,
u.admin
直接报错所以stackoverflow
http://stackoverflow.com/questions/9957058/undefined-method-admin-when-trying-to-add-an-admin-user
最后竟然成功了,再试一下 rails c
u = User.first u.admin u.admin = true u.save u
2.2.0 :006 > u
=> #<User id: 1, email: "2243980491@qq.com", encrypted_password: "$2a$10$j8LlDiW7ce7zWUoHR0jJq.hoOvUxB7ABZZ.Joq8P4jT...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 1, current_sign_in_at: "2016-02-19 15:14:10", last_sign_in_at: "2016-02-19 15:14:10", current_sign_in_ip: "::1", last_sign_in_ip: "::1", created_at: "2016-02-19 15:14:10", updated_at: "2016-02-19 15:19:37", admin: true>
成功了,admin 出现了。