Ruby on rails 由于字段不存在,创建不保存记录
我想不出来。我在Ruby应用程序上运行Postgres,我的模式如下所示:Ruby on rails 由于字段不存在,创建不保存记录,ruby-on-rails,ruby,postgresql,Ruby On Rails,Ruby,Postgresql,我想不出来。我在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 "u
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
current_shop.amazons.create(
marketplace: marketplace,
seller_id: seller_id,
auth_token: auth_token,
shipping_countries: countries,
shop_id: current_shop.id)
current_shop.amazons.create(
marketplace: marketplace,
seller_id: seller_id,
auth_token: auth_token,
shipping_countries: countries,
shop_id: current_shop.id)
我确实从Amazons
表中删除了shopify\u域。但我运行了迁移,正如您在我的模式中所看到的,它已经消失了
但是,我尝试创建一条新记录,并收到以下错误消息:
NoMethodError(未定义的方法shopfify#u域用于#
我正在创建新的Amazon
记录,方法是将其范围限定到商店,如下所示:
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
current_shop.amazons.create(
marketplace: marketplace,
seller_id: seller_id,
auth_token: auth_token,
shipping_countries: countries,
shop_id: current_shop.id)
current_shop.amazons.create(
marketplace: marketplace,
seller_id: seller_id,
auth_token: auth_token,
shipping_countries: countries,
shop_id: current_shop.id)
使用current_shop
作为从会话中获取当前商店的方法。它工作正常
我在哪里迷路了
编辑:我去检查了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
然后app/controllers/concerns/amazon\u creds\u concern.rb:23:in
save_amazon_creds(marketplace, seller_id, auth_token, countries)
最后app/controllers/concerns/amazon\u creds\u concern.rb:55:in
save_amazon_creds(marketplace, seller_id, auth_token, countries)
加上
去你的亚马逊课堂
您要么需要该类中的shopify_域(或者使用转发),要么需要从Amazon类中删除include
顺便说一句,shopify_token也一样
请展示你的Amazon
模型。有一种可能性,你使用的是shopify\u domain
。如果你展示实际的错误堆栈和代码行出现的位置,可能会有所帮助。当然,我用更多信息更新了帖子。我想Amazon\u creds\u concern
中的一种方法就是抛出错误。如果我在你之前,我想我会先做一个放置当前商店。亚马逊
,放置市场
,放置卖家id
,等等。就在当前商店之前。亚马逊。创建
呼叫,看看谁是罪魁祸首。为了节省键入时间,你可以一个一个地添加它们,直到你发现问题的根源。哇哦太感谢你了,谁知道要花多长时间!