{"action":"created","issue":{"url":"https://api.github.com/repos/madzhuga/rails_workflow/issues/15","repository_url":"https://api.github.com/repos/madzhuga/rails_workflow","labels_url":"https://api.github.com/repos/madzhuga/rails_workflow/issues/15/labels{/name}","comments_url":"https://api.github.com/repos/madzhuga/rails_workflow/issues/15/comments","events_url":"https://api.github.com/repos/madzhuga/rails_workflow/issues/15/events","html_url":"https://github.com/madzhuga/rails_workflow/pull/15","id":132551837,"number":15,"title":"Fix JSON importing bug related to ActiveModelSerializer settings","user":{"login":"edave","id":18583,"avatar_url":"https://avatars.githubusercontent.com/u/18583?v=3","gravatar_id":"","url":"https://api.github.com/users/edave","html_url":"https://github.com/edave","followers_url":"https://api.github.com/users/edave/followers","following_url":"https://api.github.com/users/edave/following{/other_user}","gists_url":"https://api.github.com/users/edave/gists{/gist_id}","starred_url":"https://api.github.com/users/edave/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edave/subscriptions","organizations_url":"https://api.github.com/users/edave/orgs","repos_url":"https://api.github.com/users/edave/repos","events_url":"https://api.github.com/users/edave/events{/privacy}","received_events_url":"https://api.github.com/users/edave/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-02-09T22:14:14Z","updated_at":"2016-02-09T22:15:02Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/madzhuga/rails_workflow/pulls/15","html_url":"https://github.com/madzhuga/rails_workflow/pull/15","diff_url":"https://github.com/madzhuga/rails_workflow/pull/15.diff","patch_url":"https://github.com/madzhuga/rails_workflow/pull/15.patch"},"body":"This PR fixes an issue where the client application may have ActiveModelSerializer configured to store associated records in the root of the JSON, rather than embedded within each record. This results in the `operations` of the exported JSON file to be at the root, e.g.,:\r\n```\r\n{\"process_template\":\r\n   {\"uuid\":\"8a85a519-8644-6146-f9aa-39ec1348a8c2\",\r\n     \"title\":\"My Process\",\r\n     ... \r\n    \"operation_ids\":[1,2,3]\r\n   },\r\n \"operations\": [ \r\n  { operation 1},\r\n  { operation 2},\r\n  { operation 3}\r\n  ]\r\n}\r\n```\r\nWhen you try to import this type of file back into Rails Workflow, the ProcessImporter class throws an exception on [this line](https://github.com/madzhuga/rails_workflow/blob/master/app/services/rails_workflow/process_importer.rb#L21) because `@json['operations']` is nil\r\n\r\nThis is caused by having an Active Model Serializer `config` like:\r\n```\r\nActiveModel::Serializer.setup do |config|\r\n  config.embed = :ids\r\n  config.embed_in_root = true\r\nend\r\n```\r\nUnfortunately there does not appear to be a way to configure a Rails Engine to not use the parent application's ActiveModelSerializer settings (or at least, I could not make it work by including an initializer in Rails Workflow that explicitly reset the `embed` values back to normal), so the `ProcessImporter` now copies the `operations` array back into the `process_template` hash if it is detected at root."},"comment":{"url":"https://api.github.com/repos/madzhuga/rails_workflow/issues/comments/182103176","html_url":"https://github.com/madzhuga/rails_workflow/pull/15#issuecomment-182103176","issue_url":"https://api.github.com/repos/madzhuga/rails_workflow/issues/15","id":182103176,"user":{"login":"edave","id":18583,"avatar_url":"https://avatars.githubusercontent.com/u/18583?v=3","gravatar_id":"","url":"https://api.github.com/users/edave","html_url":"https://github.com/edave","followers_url":"https://api.github.com/users/edave/followers","following_url":"https://api.github.com/users/edave/following{/other_user}","gists_url":"https://api.github.com/users/edave/gists{/gist_id}","starred_url":"https://api.github.com/users/edave/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edave/subscriptions","organizations_url":"https://api.github.com/users/edave/orgs","repos_url":"https://api.github.com/users/edave/repos","events_url":"https://api.github.com/users/edave/events{/privacy}","received_events_url":"https://api.github.com/users/edave/received_events","type":"User","site_admin":false},"created_at":"2016-02-09T22:15:02Z","updated_at":"2016-02-09T22:15:02Z","body":"By the way, thank you for such an awesome Rails Engine!"}}