{"action":"created","issue":{"url":"https://api.github.com/repos/justinfrench/formtastic/issues/1151","labels_url":"https://api.github.com/repos/justinfrench/formtastic/issues/1151/labels{/name}","comments_url":"https://api.github.com/repos/justinfrench/formtastic/issues/1151/comments","events_url":"https://api.github.com/repos/justinfrench/formtastic/issues/1151/events","html_url":"https://github.com/justinfrench/formtastic/issues/1151","id":84961189,"number":1151,"title":"collection_from_enum I18n unusable with has_many nested forms","user":{"login":"fabien-michel","id":1167556,"avatar_url":"https://avatars.githubusercontent.com/u/1167556?v=3","gravatar_id":"","url":"https://api.github.com/users/fabien-michel","html_url":"https://github.com/fabien-michel","followers_url":"https://api.github.com/users/fabien-michel/followers","following_url":"https://api.github.com/users/fabien-michel/following{/other_user}","gists_url":"https://api.github.com/users/fabien-michel/gists{/gist_id}","starred_url":"https://api.github.com/users/fabien-michel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fabien-michel/subscriptions","organizations_url":"https://api.github.com/users/fabien-michel/orgs","repos_url":"https://api.github.com/users/fabien-michel/repos","events_url":"https://api.github.com/users/fabien-michel/events{/privacy}","received_events_url":"https://api.github.com/users/fabien-michel/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-06-04T07:31:36Z","updated_at":"2015-06-25T10:02:13Z","closed_at":"2015-06-25T10:02:13Z","body":"the ```collection_from_enum``` method try to fetch translation with the following key: \r\n```ruby\r\nkey = \"activerecord.attributes.#{object_name}.#{method_name.pluralize}.#{name}\"\r\n```\r\nIn case where the field is in a has_many nested (eg: with cocoon) form, object_name can be like this : \r\n\r\n```ruby\r\ncar[wheels_attributes][0]\r\n```\r\nSo it is impossible to use the translation.\r\nI suggest to change object_name by ```model_name.underscore``` or something like this to obtain just the model name as expected to use in the translation yml file."},"comment":{"url":"https://api.github.com/repos/justinfrench/formtastic/issues/comments/115196177","html_url":"https://github.com/justinfrench/formtastic/issues/1151#issuecomment-115196177","issue_url":"https://api.github.com/repos/justinfrench/formtastic/issues/1151","id":115196177,"user":{"login":"justinfrench","id":5240,"avatar_url":"https://avatars.githubusercontent.com/u/5240?v=3","gravatar_id":"","url":"https://api.github.com/users/justinfrench","html_url":"https://github.com/justinfrench","followers_url":"https://api.github.com/users/justinfrench/followers","following_url":"https://api.github.com/users/justinfrench/following{/other_user}","gists_url":"https://api.github.com/users/justinfrench/gists{/gist_id}","starred_url":"https://api.github.com/users/justinfrench/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justinfrench/subscriptions","organizations_url":"https://api.github.com/users/justinfrench/orgs","repos_url":"https://api.github.com/users/justinfrench/repos","events_url":"https://api.github.com/users/justinfrench/events{/privacy}","received_events_url":"https://api.github.com/users/justinfrench/received_events","type":"User","site_admin":false},"created_at":"2015-06-25T10:02:13Z","updated_at":"2015-06-25T10:02:13Z","body":"Okay, I've been looking into this a bit more. My first step was checking what simple_form does. They have a \"won't fix\" issue plataformatec/simple_form#1063 which suggests that there are some issues in Rails for enums on user input (like forms).\r\n\r\nI believe we _can_ patch Formtastic using `model_name.downcase` or a modification of `object_name` to suit your needs, but I'm not convinced that we _should_:\r\n\r\n1. What _are_ the Rails team issues with Enum — will the implementation change?\r\n2. Is the simple_form issue similar to the formtastic one, or different? How?\r\n3. What is the _right_ i18n key? `post.author.statuses` or `author.statuses` or something else?\r\n4. What _don't I know_ about this problem that might introduce a bug for others?\r\n\r\nSo, for now, I think my suggestion is to write your own monkey patch in an initializer. Something like this:\r\n\r\n```ruby\r\n# config/initializers/formtastic_i18n_patch.rb\r\nmodule Formtastic::Inputs::Base::Collections\r\n  def collection_from_enum\r\n    if collection_from_enum?\r\n      method_name = method.to_s\r\n      enum_options_hash = object.defined_enums[method_name]\r\n      enum_options_hash.map do |name, value| \r\n        # patched line below\r\n        key = \"activerecord.attributes.#{model_name.downcase}.#{method_name.pluralize}.#{name}\"\r\n        label = ::I18n.translate(key, :default => name.humanize) \r\n        [label, name]\r\n      end\r\n    end\r\n  end\r\nend\r\n```\r\n\r\nI'm not interested in merging a fix into master at this time though. Closing this ticket for now, but please feel free to re-open if you need a hand with the patch. "}}