-
Notifications
You must be signed in to change notification settings - Fork 21.9k
Remember the stored attributes in a config attribute. #5412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This allows you to retrieve the list of attributes you've defined. Usable for e.g. selects in the view, or interators based on the attributes you wish to store in the serialized column.
My thoughts are there a constant with the list of attributes would probably do in this case. Anyway, in case it goes in, I'd have to ask you to squash your commits into one. Thanks! |
Will gladly squash the commits. And I will wait a couple of days for the others to chime in with regards to the chosen solution. |
Why are we using config_attribute instead of class_attribute? |
@josevalim good question. We have this code using I think this pull request will be useful. 👍 @tilsammans could you try to use |
It seems @jonleighton added it when he added ActiveRecord::Model. |
@josevalim there is some documentation here The point was to create something similar to module Foo
included do
class_attribute :foo
end
end
module ActiveRecord::Model
include Foo # we're not in a class, so class_attribute isn't defined
end The reason that it's in AM is because some AM modules use it. I'm happy to hear idea for other, nicer solutions :) |
@jonleighton If you |
Hmm good point. I will check that. IIRC there was some issue with relying on that behaviour but I can't remember the details so it's worth revisiting. |
@josevalim I think part of it was that I wanted to make it possible to set config stuff on |
@tilsammans your proposed pull request is ok to be merged in, but it'd need minor changes before. Could you please:
Thanks! |
remove backported string interpolation
This allows you to retrieve the list of attributes you've defined. Usable for e.g. selects in the view, or interators based on the attributes you wish to store in the serialized column.
Also require the needed files.
This reverts commit 3ff1102.
ActiveRecord::Store is a Module, not a Class, so class_attribute will not work. What to do? |
@tilsammans well, ok for Your pull request is not applying cleanly anymore, can you please rebase from current master, and squash your commits into one, so we can merge? Thanks. |
Added `stored_attributes` hash which contains the attributes stored using ActiveRecord::Store. This allows you to retrieve the list of attributes you've defined. class User < ActiveRecord::Base store :settings, accessors: [:color, :homepage] end User.stored_attributes[:settings] # [:color, :homepage]
This allows you to retrieve the list of attributes you've defined.
Usable for e.g. selects in the view, or interators based on the
attributes you wish to store in the serialized column.
It follows the serialize API, with its serialized_attributes hash.