Groups
Sign in
Groups
Ruby on Rails: Core
Conversations
About
Send feedback
Help
[Feature][ActiveRecord] Add custom types to store_accessor
22 views
Skip to first unread message
Tiago Babo
unread,
May 6, 2019, 11:48:44 AM
5/6/19
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Ruby on Rails: Core
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
unread,
May 7, 2019, 11:35:00 AM
5/7/19
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Ruby on Rails: Core
Hey Tiago!
IMO, the feature could be a great addition to Rails. And the number of times it has been proposed kinda proves it:
-
https://github.com/rails/rails/commit/85b64f98d100d37b3a232c315daa10fad37dccdc#commitcomment-650592
(the very early days of store accessors)
-
https://github.com/rails/rails/pull/18942
(extracted into a gem
store_attribute
)
-
https://github.com/rails/rails/pull/26882
(still open).
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
Reply all
Reply to author
Forward
0 new messages