NoMethodError:未定义的方法`admin =&#39;对于#<user:0x00000002ceae30>

时间:2016-08-19 09:08:52

标签: mysql ruby-on-rails devise rails-admin rails-console

  

目前我使用的是最新版本的rails_admin和设计gem并且必须有两名signed_in用户

Running via Spring preloader in process 4912
Loading development environment (Rails 5.0.0.1)
2.3.1 :001 > u = User.first
User Load (0.4ms)  SELECT  "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT ?  [["LIMIT", 1]]
=> #<User id: 1, email: "dhami.khawas@gmail.com", created_at: "2016-08-15 10:26:16", updated_at: "2016-08-16 12:48:11"> 
2.3.1 :002 > u = User.last
User Load (0.7ms)  SELECT  "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT ?  [["LIMIT", 1]]
=> #<User id: 2, email: "linux@gmail.com", created_at: "2016-08-16 10:03:10", updated_at: "2016-08-19 08:18:23"> 

2.3.1:003

  

如何将其中任何一位作为管理员用户?我尝试在下面运行但最终出错了。

2.3.1 :004 > u.admin
NoMethodError: undefined method `admin' for #<User:0x00000002d3dbf8>
from /home/bikal/.rvm/gems/ruby-2.3.1/gems/activemodel-5.0.0.1/lib/active_model/attribute_methods.rb:433:in `method_missing'
from (irb):4
from /home/bikal/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands/console.rb:65:in `start'
from /home/bikal/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands/console_helper.rb:9:in `start'
from /home/bikal/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:78:in `console'
from /home/bikal/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /home/bikal/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in `<top (required)>'
from /home/bikal/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
from /home/bikal/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `block in require'
from /home/bikal/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
from /home/bikal/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
from /home/bikal/workspace/concert_nepal/bin/rails:9:in `<top (required)>'
from /home/bikal/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
from /home/bikal/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `block in load'
from /home/bikal/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
from /home/bikal/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
from /home/bikal/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/commands/rails.rb:6:in `call'
from /home/bikal/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/command_wrapper.rb:38:in `call'
from /home/bikal/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:191:in `block in serve'
from /home/bikal/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:161:in `fork'
from /home/bikal/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:161:in `serve'
from /home/bikal/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:131:in `block in run'
from /home/bikal/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:125:in `loop'
from /home/bikal/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:125:in `run'
from /home/bikal/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application/boot.rb:19:in `<top (required)>'
from /home/bikal/.rvm/rubies/ruby-2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/bikal/.rvm/rubies/ruby-2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
2.3.1 :005 > 

0 个答案:

没有答案