Right now one can use the attributes API for custom types, but it doesn’t work with store attributes. The following method would fix that:
store_accessor :preferences, :show_avatar, :boolean, default: true
``
I’ve implemented a concern with this logic for a project I’m working on, and it works great.
Do you think it would be a nice addition to Rails?
Vlad_Dem
(Vlad Dem)
May 7, 2019, 3:34pm
2
Hey Tiago!
IMO, the feature could be a great addition to Rails. And the number of times it has been proposed kinda proves it:
There is also another gem with a bit different API (https://github.com/byroot/activerecord-typedstore ).
store_accessor :preferences, :show_avatar, :boolean, default: true
This API looks a bit confusing: how to distinguish between boolean
as attribute name and as a type? I mean, the following code is valid in Rails:
store_accessor :preferences, :show_avatar, :boolean
noahhorton
(Noah Horton)
November 18, 2022, 3:49am
3
I wanted to bring this one back up yet again. Any chance that core would accept a PR around this? Looking at the code, this would not be a hard change. I don’t want to put in the work if it is unlikely to make it, and it looks like prior attempts have been rejected.