gpt4 book ai didi

ruby-on-rails - 未定义的方法 `to_i' 与来自控制台的设计

转载 作者:行者123 更新时间:2023-12-05 00:24:54 24 4
gpt4 key购买 nike

我第一次尝试设计。我创建了一个基本的登录/注销系统,并试图从控制台创建一些对象并注意到一些奇怪的事情:

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

最佳答案

简单的解决方法是将其添加到 .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

关于ruby-on-rails - 未定义的方法 `to_i' 与来自控制台的设计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25545330/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com