{"action":"created","issue":{"url":"https://api.github.com/repos/sferik/rails_admin/issues/2615","repository_url":"https://api.github.com/repos/sferik/rails_admin","labels_url":"https://api.github.com/repos/sferik/rails_admin/issues/2615/labels{/name}","comments_url":"https://api.github.com/repos/sferik/rails_admin/issues/2615/comments","events_url":"https://api.github.com/repos/sferik/rails_admin/issues/2615/events","html_url":"https://github.com/sferik/rails_admin/issues/2615","id":149790529,"number":2615,"title":"Virtual Enum Field Not Working","user":{"login":"cec","id":386155,"avatar_url":"https://avatars.githubusercontent.com/u/386155?v=3","gravatar_id":"","url":"https://api.github.com/users/cec","html_url":"https://github.com/cec","followers_url":"https://api.github.com/users/cec/followers","following_url":"https://api.github.com/users/cec/following{/other_user}","gists_url":"https://api.github.com/users/cec/gists{/gist_id}","starred_url":"https://api.github.com/users/cec/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cec/subscriptions","organizations_url":"https://api.github.com/users/cec/orgs","repos_url":"https://api.github.com/users/cec/repos","events_url":"https://api.github.com/users/cec/events{/privacy}","received_events_url":"https://api.github.com/users/cec/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-04-20T14:49:51Z","updated_at":"2016-05-13T08:40:18Z","closed_at":null,"body":"Hi,\r\n\r\nhaving issues to add a virtual field (_change_importance_) of type enum for the edit section of one model.\r\n\r\nThe values for the virtual enum are meant to be provided by\r\n\r\n```\r\n  def change_importance_enum\r\n    {little: 0, a_lot: 1}\r\n  end\r\n```\r\n\r\nand here is the configuration of the field\r\n\r\n```\r\nfield :change_importance, :enum do\r\n  formatted_value { 0 }\r\nend\r\n```\r\n\r\nI put 0 as formatted_value, because there is no actual data to provide a value for _change_importance_: the value is volatile and has meaning only in the scope of the current request.\r\nI'm overriding the edit action of this model by placing my own controller in front of MainController from routes.rb. In my controller I determine whether or not to run a certain routine depending on the value of _change_importance_.\r\n\r\n**The problem is** that when rendering, `_form_enumeration` calls `field.form_value`, which calls `form_default_value`, which calls `value`, which raises the usual error of a virtual field not declaring a formatted_value.\r\n\r\nCan I override `form_value` for a specific field somehow?\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/sferik/rails_admin/issues/comments/218984595","html_url":"https://github.com/sferik/rails_admin/issues/2615#issuecomment-218984595","issue_url":"https://api.github.com/repos/sferik/rails_admin/issues/2615","id":218984595,"user":{"login":"slbug","id":108694,"avatar_url":"https://avatars.githubusercontent.com/u/108694?v=3","gravatar_id":"","url":"https://api.github.com/users/slbug","html_url":"https://github.com/slbug","followers_url":"https://api.github.com/users/slbug/followers","following_url":"https://api.github.com/users/slbug/following{/other_user}","gists_url":"https://api.github.com/users/slbug/gists{/gist_id}","starred_url":"https://api.github.com/users/slbug/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/slbug/subscriptions","organizations_url":"https://api.github.com/users/slbug/orgs","repos_url":"https://api.github.com/users/slbug/repos","events_url":"https://api.github.com/users/slbug/events{/privacy}","received_events_url":"https://api.github.com/users/slbug/received_events","type":"User","site_admin":false},"created_at":"2016-05-13T08:40:18Z","updated_at":"2016-05-13T08:40:18Z","body":"Similar issue. Rails 5.rc1, rails_admin from master\r\n\r\nModel: \r\n\r\n```ruby\r\n  class User < ApplicationRecord\r\n    attr_reader :role\r\n  end \r\n```\r\n\r\n```ruby\r\n  config.model User do\r\n    include_fields :user_name, :role\r\n\r\n    field :role, :enum do\r\n      enum do\r\n        ['user', 'admin']\r\n      end\r\n\r\n      pretty_value\r\n         bindings[:object].display_role\r\n      end\r\n    end\r\n  end\r\n```\r\n\r\nAnd it just crashes ```NoMethodError: undefined method `defined' for nil:NilClass``` on <pre>\"rails_admin-122cbf0b4fdd/lib/rails_admin/config/has_fields.rb\", line 92, in block in fields</pre>"}}