不節能想不通這是爲什麼不節省..保存在控制器
我已經縮短我的簡碼,留下了end
和其他非重要的事情。
我有這個擊中在控制器:
create_barbie = Barbie.new(params.require(:barbie).permit(:merchant_id,
:auth_token,:marketplace))
huh = create_barbie.save! #this is returning ActiveRecord::RecordNotSaved
#(Failed to save the record)
失敗create_barbie
之前看起來是這樣的:
id: nil, merchant_id: "A340I3XXXX", auth_token: "13245", marketplace:
"abcded", created_at: nil, updated_at: nil, shopify_domain: nil, shop_id:
nil, three_speed: nil>
所以我params
要過來的罰款,並越來越稀少,只是一些原因記錄沒有保存?
在我Barbie
模型我有以下幾點:
class Barbie < ActiveRecord::Base
belongs_to :shop
validates :merchant_id, presence: true
validates :auth_token, presence: true
before_save :assign_three_speed
NON_US_MARKETPLACES = ["1234", "abcd"]
在Barbie
模型內的私有方法我有這樣的:
private
def assign_three_speed
if NON_US_MARKETPLACES.include?(marketplace)
self.three_speed = false
else
self.three_speed = true
end
end
所有的數據是正確的,字段設置,它只是沒有保存..不知道爲什麼?
在'create_barbie.save'後面檢查'create_barbie.errors' –
我現在要!!我不知道如何去他們..我使用'huh.inspect',它只是給我真/假 – ToddT