over 1 year ago

objective
做job-listing-4的發現,掉在同樣的步驟裡面(如下圖),但狀況不太一樣。


在做上面的步驟時,出現如下資料:
silvia@xiaoxiuliande-MacBook-Pro ⮀ ~/job4/job-listing ⮀ ⭠ step2± ⮀ rails console
Running via Spring preloader in process 1470
Loading development environment (Rails 5.0.0)
2.3.1 :001 > u = User.first
User Load (0.1ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT ? [["LIMIT", 1]]
=> nil
2.3.1 :002 > u.is_admin = true
NoMethodError: undefined method is_admin=' for nil:NilClass
from (irb):2
from /Users/silvia/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/commands/console.rb:65:in
start'
from /Users/silvia/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/commands/console_helper.rb:9:in start'
from /Users/silvia/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:78:in
console'
from /Users/silvia/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:49:in run_command!'
from /Users/silvia/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/commands.rb:18:in
'
from /Users/silvia/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in require'
:
:
:
2.3.1 :003 > u.save
NoMethodError: undefined method
save' for nil:NilClass
from (irb):3
from /Users/silvia/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/commands/console.rb:65:in start'
from /Users/silvia/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/commands/console_helper.rb:9:in
start'
from /Users/silvia/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:78:in console'
from /Users/silvia/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:49:in
run_command!'
from /Users/silvia/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/commands.rb:18:in <top (required)>'
from /Users/silvia/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in
require'
from /Users/silvia/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `block in require'
:

:

:

2.3.1 :004 > exit

解決的方法:
1.請在http://localhost:3000/上 註冊自己的資料,因自己是第一個使用者 user,也就是管理者(admin)。
2.再執行
rails console
u = User.first
u.is_admin =true
u.save
exit
正確畫面就會如下

Reflective
怎麼會又掉進去同樣的坑呢?原來還不是很了解,編程的規則。但相信總可以解決。

Interpretive
有時沒有錯誤,並非真的了解,感謝每個坑。

Decisional
明天也加油!!!

← 重做Rails 實戰:招聘網站(管理員)-bug1 重做 Rails實戰:招聘網站 -bug3 →
 
comments powered by Disqus