2
有沒有辦法使用ActiveRecord::Store而不聲明訪問?ActiveRecord ::存儲沒有訪問器?
用例是我希望用戶能夠將任何變量附加到URL中,然後將該鍵/值與該記錄一起保存。
例如,有人可能會做: http://example.com/response?order_number=12345&manager=Johnny&used_valet=true
所以我想order_number
,manager
,並used_valet
被保存在記錄一個variables
列。但是每個用戶都會有一組他們想要存儲的變量。
現在,我有這樣的:
class Response < ActiveRecord::Base
store :variables
end
但這樣做會引發unknown attribute
錯誤:
$ Response.create(order_number: '12345')
ActiveRecord::UnknownAttributeError: unknown attribute: order_number