gpt4 book ai didi

ruby-on-rails - 由于字段不存在而创建不保存记录

转载 作者:行者123 更新时间:2023-11-29 13:14:50 25 4
gpt4 key购买 nike

无法解决这个问题。我在 Ruby 应用程序上运行 Postgres,我的架构如下所示:

ActiveRecord::Schema.define(version: 20180518200146) do
create_table "amazons", force: :cascade do |t|
t.text "auth_token"
t.text "marketplace"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "shop_id"
t.boolean "three_speed"
t.text "seller_id"
t.string "shipping_countries", array: true
end

create_table "shops", force: :cascade do |t|
t.string "shopify_domain", null: false
t.string "shopify_token", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "paid", default: false
t.boolean "setup", default: false
t.string "carrier_id"
t.index ["shopify_domain"], name: "index_shops_on_shopify_domain", unique: true
end

add_foreign_key "amazons", "shops"
end

我确实删除了 shopify_domain来自 Amazons table 。但我运行了该迁移,正如您在我的架构中看到的那样,它消失了。

但是我尝试了 create一条新记录,我收到此错误消息: NoMethodError (undefined method shopify_domain for #<Amazon:0x000000041fb9c8>

我正在创建新的 Amazon记录,通过像这样将其范围限定到商店:

current_shop.amazons.create(
marketplace: marketplace,
seller_id: seller_id,
auth_token: auth_token,
shipping_countries: countries,
shop_id: current_shop.id)

current_shop是一种从 session 中获取当前商店的方法。它工作正常。

我哪里误入歧途了?

编辑:我去检查了 PG 以确保,该字段也不是他们的。这是 PG 的内容:

 id                 | bigint                      | not null default nextval('amazons_id_seq'::regclass)
auth_token | text |
marketplace | text |
created_at | timestamp without time zone | not null
updated_at | timestamp without time zone | not null
shop_id | integer |
three_speed | boolean |
seller_id | text |
shipping_countries | character varying[] |

编辑:这里是 Amazon型号

class Amazon < ActiveRecord::Base
include ShopifyApp::SessionStorage
belongs_to :shop
end

然后这是整个错误信息:

NoMethodError (undefined method `shopify_domain' for #
<Amazon:0x000000041fb9c8>
Did you mean? shop_id_change):

app/controllers/concerns/amazon_creds_concern.rb:55:in `save_amazon_creds'
app/controllers/concerns/amazon_creds_concern.rb:23:in `create_amazon_client'
app/controllers/amazon_creds_controller.rb:9:in `amazon_credentials_check'

然后是与错误消息匹配的代码行,从下往上:app/controllers/amazon_creds_controller.rb:9:in amazon_credentials_check

render json: {amazon_creds_status: create_amazon_client(marketplace, seller_id, auth_token, countries), countries: countries.blank?}

然后app/controllers/concerns/amazon_creds_concern.rb:23:in

save_amazon_creds(marketplace, seller_id, auth_token, countries)

最后app/controllers/concerns/amazon_creds_concern.rb:55:in

current_shop.amazons.create(
marketplace: marketplace,
seller_id: seller_id,
auth_token: auth_token,
shipping_countries: countries,
shop_id: current_shop.id)

最佳答案

include ShopifyApp::SessionStorage

添加

validates :shopify_domain, presence: true, uniqueness: true

到您的亚马逊类(class)。

您要么需要该类中的 shopify_domain(或使用转发),要么需要从 Amazon 类中删除 include。

顺便说一句,shopify_token 也是如此。

https://github.com/Shopify/shopify_app/blob/master/lib/shopify_app/session/session_storage.rb

关于ruby-on-rails - 由于字段不存在而创建不保存记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50419171/

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