0.0
No commit activity in last 3 years
No release in over 3 years
Changes the return value of enums to symbols.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 4.1.0
 Project Readme

enum_to_sym

Ruby on Rails added support for enum columns in ActiveRecord in version 4.1.

Unfortunately, the return value of an enum attribute is a string which seems inconsistent with the rest of the feature and it's not clear if this will get changed.

class Foo < ActiveRecord::Base
  enum status: [:foo, :bar]
end

> foo = Foo.new(status: :bar)
> foo.status  # => "bar" 👎

This gem changes that behavior so that enum attributes return symbols instead. It also adds an is?(name) method as an alternative based on a comment made in this thread.

class Foo < ActiveRecord::Base
  enum status: [:foo, :bar]
end

> foo = Foo.new(status: :bar)
> foo.status  # => :bar 👍
> foo.is?(:bar) # => true

Add this to your gemfile and your enum attributes will return as symbols.

gem 'enum_to_sym'