{"action":"opened","issue":{"url":"https://api.github.com/repos/nathanvda/cocoon/issues/273","labels_url":"https://api.github.com/repos/nathanvda/cocoon/issues/273/labels{/name}","comments_url":"https://api.github.com/repos/nathanvda/cocoon/issues/273/comments","events_url":"https://api.github.com/repos/nathanvda/cocoon/issues/273/events","html_url":"https://github.com/nathanvda/cocoon/issues/273","id":62775513,"number":273,"title":"File upload renders json response in browser","user":{"login":"justinxreese","id":150839,"avatar_url":"https://avatars.githubusercontent.com/u/150839?v=3","gravatar_id":"","url":"https://api.github.com/users/justinxreese","html_url":"https://github.com/justinxreese","followers_url":"https://api.github.com/users/justinxreese/followers","following_url":"https://api.github.com/users/justinxreese/following{/other_user}","gists_url":"https://api.github.com/users/justinxreese/gists{/gist_id}","starred_url":"https://api.github.com/users/justinxreese/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justinxreese/subscriptions","organizations_url":"https://api.github.com/users/justinxreese/orgs","repos_url":"https://api.github.com/users/justinxreese/repos","events_url":"https://api.github.com/users/justinxreese/events{/privacy}","received_events_url":"https://api.github.com/users/justinxreese/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-03-18T19:12:46Z","updated_at":"2015-03-18T19:12:46Z","closed_at":null,"body":"I'm adding a file upload form with cocoon. I've removed some things for clarity and privacy, but this is hopefully enough. Here is the diff and the new attached_file_fields partial\r\n\r\n```diff\r\ndiff --git a/app/controllers/work_groups_controller.rb b/app/controllers/work_groups_controller.rb\r\nindex 26bb1f4..e691740 100644\r\n--- a/app/controllers/work_groups_controller.rb\r\n+++ b/app/controllers/work_groups_controller.rb\r\n@@ -271,6 +271,10 @@ class WorkGroupsController < ApplicationController\r\n                                          :experience, :notes\r\n+                                         attached_files_attributes: [:id, :attachable_id,\r\n+                                           :attachable_type, :name, :type,\r\n+                                           :file, :work_group_id,\r\n+                                           :size, :url, :_destroy],\r\n                                          redacted_things_attributes: [:id],\r\n\r\ndiff --git a/app/models/attachment.rb b/app/models/attachment.rb\r\nindex 3961a01..ebb236b 100644\r\n--- a/app/models/attachment.rb\r\n+++ b/app/models/attachment.rb\r\n@@ -1,4 +1,5 @@\r\n class Attachment < ActiveRecord::Base\r\n+  belongs_to :work_group\r\n   belongs_to :attachable, polymorphic: true\r\n   belongs_to :user\r\n   mount_uploader :file, AttachmentUploader\r\n\r\ndiff --git a/app/models/work_group.rb b/app/models/work_group.rb\r\nindex cc1942d..d7eb409 100644\r\n--- a/app/models/work_group.rb\r\n+++ b/app/models/work_group.rb\r\n@@ -8,6 +8,7 @@ class WorkGroup < ActiveRecord::Base\r\n   has_many :attached_files, -> { order('created_at DESC') }, class_name: 'Attachment'\r\n+  accepts_nested_attributes_for :attached_files, allow_destroy: true, reject_if: lambda {|a| a[:file].blank?}\r\n\r\ndiff --git a/app/views/work_groups/new.html.erb b/app/views/work_groups/new.html.erb\r\nindex cb34e42..c4c942c 100644\r\n--- a/app/views/work_groups/new.html.erb\r\n+++ b/app/views/work_groups/new.html.erb\r\n@@ -26,7 +26,8 @@\r\n       <strong>Success!</strong> Your progress has been saved.\r\n   </div>\r\n \r\n-<%= simple_form_for @work_group, html: {id: :new_work_group}, remote: true, format: :json do |f| %>\r\n+<%= simple_form_for @work_group, html: {id: :new_work_group, multipart: true}, remote: true, format: :json do |f| %>\r\n+  <%= token_tag %>\r\n   <div class=\"onboarding-wizard\">\r\n\r\ndiff --git a/app/views/work_groups/steps/_step3.html.erb b/app/views/work_groups/steps/_step3.html.erb\r\nindex 4be9b01..588aa5a 100644\r\n--- a/app/views/work_groups/steps/_step3.html.erb\r\n+++ b/app/views/work_groups/steps/_step3.html.erb\r\n@@ -103,8 +103,20 @@\r\n               </tr>\r\n             </thead>\r\n+            <tbody id=\"work-group-files-3\">\r\n+              <%= f.simple_fields_for :attached_files, f.object.attached_files.build do |attached_file| %>\r\n+                <%= render 'attached_file_fields', f: attached_file %>\r\n+              <% end %>\r\n+            </tbody>\r\n+          </table>\r\n-          <a href=\"#\" class=\"btn btn-primary pull-right\" style=\"margin-top: 20px\">+ Add a Report</a>\r\n+              <%= link_to_add_association '+ Add a Report', f, :attached_files, {:\"data-association-insertion-node\" => \"tbody#work-group-files-3\", :\"data-association-insertion-method\" => \"append\"} %>\r\n\r\n```\r\n\r\nPartial\r\n```erb\r\n<tr class=\"nested-fields\">\r\n  <td>\r\n    <%= f.input :id, as: :hidden %>\r\n    <%= f.association :work_group, as: :hidden, input_html: {class: :work_group_association} %>\r\n    <%= f.file_field :file %>\r\n  </td>\r\n  <td>\r\n    <%= link_to_remove_association image_tag('remove-member.png'), f %>\r\n  </td>\r\n</tr>\r\n```\r\n\r\nWhen I submit the form, instead of handling the response with the javascript (as it did before), it is rendering the json response in the browser. Not sure what is going on here."}}