-
-
Notifications
You must be signed in to change notification settings - Fork 64
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
flags_as_attributes method? #67
Comments
This is a really good idea. Some of the internals for this are already present, but not well exposed. I will work on improving the situation. |
@mltsy - One similar feature to one part of your idea is the form builder support:
Another similar thing already in the code is:
For which I'll just copy the documentation from the code:
|
This is how I do it in the end! def attributes
super.merge(Hash[as_flag_collection('services')].as_json)
end |
Sweet Potato. This PR has almost written itself. 👯 |
I'm not sure what a good name for this really is, or the best way for it to work, but I was just writing some tests, and expecting
model.attributes
to return all my flags as individual Boolean attribute values, which of course, it did not :)My flag field is called
setup_steps
so I figured out I could rewrite the test to useselected_setup_steps
, but I still think a method to retrieve the flag values in the format of regular attributes (the same way you can set them) would be useful (i.e.{ flag1: true, flag2: true, flag3: false }
)What I'm not sure about is whether it makes more sense for that to be a model-wide method, like
model.attributes_with_flags
which would return all the normal attributes, plus additional attributes for each defined flag (regardless of how many flag fields are defined), or to make one method per flag field, likemodel.setup_steps_as_attributes
or something to that effect... that one would be marginally easier to implement at least. Any opinion?The text was updated successfully, but these errors were encountered: