我第一次尝试Devise。我已经创建了一个基本的登录/注销系统,并试图从控制台创建一些对象并注意到一些奇怪的东西:
rails c --sandbox
Loading development environment in sandbox (Rails 4.1.5)
Any modifications you make will be rolled back on exit
Frame number: 0/20
[1] » u = User.last
User Load (0.7ms) SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
(pry) output error: #<NoMethodError: undefined method `to_i' for #<Object:0x007fd988871540>>
[2] » u
(pry) output error: #<NoMethodError: undefined method `to_i' for #<Object:0x007fd988871540>>
[3] » u.id
=> 5
为什么控制台会在我的对象上抛出错误? User.last等也会发生同样的事情。
这是我的架构:
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, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.inet "current_sign_in_ip"
t.inet "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
end
答案 0 :(得分:4)
简单的工作方式是将其添加到.pryrc
module AwesomePrint
class Formatter
private
def awesome_self(object, type)
if @options[:raw] && object.instance_variables.any?
awesome_object(object)
elsif object.respond_to?(:to_hash)
awesome_hash(object.to_hash)
else
colorize(object.inspect.to_s, type)
end
end
end
end
答案 1 :(得分:2)
你是否安装了gem jazzy_hands?这就是我们的理由。