Skip to content

Instantly share code, notes, and snippets.

@amiel
Created March 22, 2013 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amiel/5224071 to your computer and use it in GitHub Desktop.
Save amiel/5224071 to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
# t.string :status, default: 'submitted'
# Contrived example
def self.status_options
%w[approved rejected submitted]
end
end
class UserDecorator < Draper::Base
decorates :user
# I've recently refactored this pattern to the Olson gem.
# See: https://github.com/carnesmedia/olson for more information.
def self.status_options_for_select
User.status_options.map { |s| [s.humanize, s] }
end
def status
model.status.humanize
end
end
ActiveAdmin.register User do
# ...
form do
f.inputs do
# So, here's an example of the problem. `f.object.status` now returns "Submitted",
# which doesn't match the actual status option: "submitted". So, the select doesn't
# have the correct status selected.
# This is sort of subtle, but one of those not-so-obvious bugs with big potential problems.
f.input :status, collection: UserDecorator.status_options_for_select
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment