{"action":"created","issue":{"url":"https://api.github.com/repos/trailblazer/cells-erb/issues/2","repository_url":"https://api.github.com/repos/trailblazer/cells-erb","labels_url":"https://api.github.com/repos/trailblazer/cells-erb/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/trailblazer/cells-erb/issues/2/comments","events_url":"https://api.github.com/repos/trailblazer/cells-erb/issues/2/events","html_url":"https://github.com/trailblazer/cells-erb/issues/2","id":109484839,"number":2,"title":"Nested model-backed form content (fields_for) gets html escaped","user":{"login":"johnlane","id":1786613,"avatar_url":"https://avatars.githubusercontent.com/u/1786613?v=3","gravatar_id":"","url":"https://api.github.com/users/johnlane","html_url":"https://github.com/johnlane","followers_url":"https://api.github.com/users/johnlane/followers","following_url":"https://api.github.com/users/johnlane/following{/other_user}","gists_url":"https://api.github.com/users/johnlane/gists{/gist_id}","starred_url":"https://api.github.com/users/johnlane/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johnlane/subscriptions","organizations_url":"https://api.github.com/users/johnlane/orgs","repos_url":"https://api.github.com/users/johnlane/repos","events_url":"https://api.github.com/users/johnlane/events{/privacy}","received_events_url":"https://api.github.com/users/johnlane/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2015-10-02T12:48:47Z","updated_at":"2016-11-19T04:24:51Z","closed_at":null,"body":"As discussed on Gitter, I have this problem where nested `fields_for` are escaped when rendered. I've been doing some research and conclude that it happens\n- only if the form is rendering a model object\n- when the nested content is concatenated to the form output buffer\n- because a different concatenate `<<` method is executed\n\n---\n\n**TL;DR** For a temporary workaround apply `$ sed -i -e '25s:):).html_safe:' $(bundle show cells-erb)/lib/cell/erb/template.rb` to cells-erb-0.0.6.\n\n---\n\nWhen the form is a model object the `concat` method in activesupport-4.2.4/lib/active_support/core_ext/string/output_safety.rb#184 is used:\n\n``` ruby\n   184:     def concat(value)\n=> 185:       super(html_escape_interpolated_argument(value))\n   186:     end\n```\n- the receiving buffer `self` is a `ActiveSupport::SafeBuffer`\n- the concatenated buffer `value` is a `String`\n\nWhen the form has no model it uses cells-4.0.2/lib/cell/view_model.rb#163\n\n``` ruby\n   163:       def <<(string)\n=> 164:         super\n   165:       end\n```\n- the receiving buffer `self` is a `Cell::ViewModel::OutputBuffer`\n- the concatenated buffer `string` is a `String`\n\nA solution to this problem is to apply `.html_safe` to the output buffer in `cells-erb-0.0.6/lib/cell/erb/template.r`:\n\n``` ruby\n 22     # this is capture copied from AV:::CaptureHelper without doing escaping.\n 23     def capture(*args)\n 24       value = nil\n 25       buffer = with_output_buffer { value = yield(*args) }\n 26 \n 27       return buffer.to_s if buffer.size > 0                                       \n 28       value # this applies for \"Beachparty\" string-only statements.\n 29     end\n\n```\n\nReplace line with\n\n``` ruby\n25      buffer = with_output_buffer { value = yield(*args).html_safe }\n```\n\n_I do not understand the code well enough to know if that is the right solution but it does solve the problem for my use-case._\n"},"comment":{"url":"https://api.github.com/repos/trailblazer/cells-erb/issues/comments/261692593","html_url":"https://github.com/trailblazer/cells-erb/issues/2#issuecomment-261692593","issue_url":"https://api.github.com/repos/trailblazer/cells-erb/issues/2","id":261692593,"user":{"login":"PeteTyldesley","id":14144032,"avatar_url":"https://avatars.githubusercontent.com/u/14144032?v=3","gravatar_id":"","url":"https://api.github.com/users/PeteTyldesley","html_url":"https://github.com/PeteTyldesley","followers_url":"https://api.github.com/users/PeteTyldesley/followers","following_url":"https://api.github.com/users/PeteTyldesley/following{/other_user}","gists_url":"https://api.github.com/users/PeteTyldesley/gists{/gist_id}","starred_url":"https://api.github.com/users/PeteTyldesley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PeteTyldesley/subscriptions","organizations_url":"https://api.github.com/users/PeteTyldesley/orgs","repos_url":"https://api.github.com/users/PeteTyldesley/repos","events_url":"https://api.github.com/users/PeteTyldesley/events{/privacy}","received_events_url":"https://api.github.com/users/PeteTyldesley/received_events","type":"User","site_admin":false},"created_at":"2016-11-19T04:24:51Z","updated_at":"2016-11-19T04:24:51Z","body":"Any ideas for alternatives to this workaround? It fixes the rendering of the fields_for but causes some strange rendering issues for the rest of my cells."}}
{"actor":{"display_login":"PeteTyldesley"}}