Skip to content

Instantly share code, notes, and snippets.

@hieunguyentrung
Created April 4, 2019 14:56
Show Gist options
  • Save hieunguyentrung/01a7f78ea64b1685b399a95917714b74 to your computer and use it in GitHub Desktop.
Save hieunguyentrung/01a7f78ea64b1685b399a95917714b74 to your computer and use it in GitHub Desktop.
enumerize
# model
# enumerizeがlocaleされている。
extend Enumerize
enumerize :account_type, in: { normal: 0, easy: 1, hard: 2, test: 3 },scope: true

# controller
@types = User.account_type.options
@types.map.with_index { |type, index| type[1] = index }

# view
<%= f.select :account_type_eq, @types %>
# model
extend Enumerize
enumerize :account_type, in: { normal: 0, easy: 1, hard: 2, test: 3 },scope: true

scope :search_by_type, -> (type) { where(type: type) }


# view
<%= f.label :search_by_type, 'タイプ:', class: 'col-md-2 control-label' %>
<%= f.select :search_by_type, User.type.options, {include_blank: true}, {class: 'form-control'} %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment