Multiple store_accessors with identical keys

Viewed 837

I have model Profile with hstore field paypal_credentials:

class Profile < ActiveRecord::Base
  ...
  store_accessor :paypal_credentials, :preapproval_key, :preapproval_url
  ...
end

Now I need to add the second hstore field named customer_paypal_credentials with identical keys. How can I use store_accessor in this way? I can't find anything about prefix/suffix functionality of store_accessor.

Thank you.

1 Answers

This is possible in Rails 6 and above: https://api.rubyonrails.org/classes/ActiveRecord/Store.html

From the doc:

class User < ActiveRecord::Base
  store :settings, accessors: [ :color, :homepage ], coder: JSON
  store :parent, accessors: [ :name ], coder: JSON, prefix: true
  store :spouse, accessors: [ :name ], coder: JSON, prefix: :partner
  store :settings, accessors: [ :two_factor_auth ], suffix: true
  store :settings, accessors: [ :login_retry ], suffix: :config
end
Related