Simon
Simon

Reputation: 751

Store strings with special characters as enum values in Rails 5

In Rails 5, the enum value type can only accept symbols, i.e. immutable "strings" with letters and digits.

How would you best use enum values in Rails, which have to be shown also with their special characters like e.g. 'Hip-Hop/Rap' included in the enum field genre?

Upvotes: 1

Views: 1024

Answers (1)

SteveTurczyn
SteveTurczyn

Reputation: 36860

you can use quotes around symbol text if it contains special characters.

[:classical, :pop, :'Hip-Hop/Rap']

Upvotes: 4

Related Questions