{"action":"created","issue":{"url":"https://api.github.com/repos/nathanvda/cocoon/issues/372","repository_url":"https://api.github.com/repos/nathanvda/cocoon","labels_url":"https://api.github.com/repos/nathanvda/cocoon/issues/372/labels{/name}","comments_url":"https://api.github.com/repos/nathanvda/cocoon/issues/372/comments","events_url":"https://api.github.com/repos/nathanvda/cocoon/issues/372/events","html_url":"https://github.com/nathanvda/cocoon/issues/372","id":161411535,"number":372,"title":"Trouble when creating a new entry inline replacing existing ones","user":{"login":"kimadactyl","id":511734,"avatar_url":"https://avatars.githubusercontent.com/u/511734?v=3","gravatar_id":"","url":"https://api.github.com/users/kimadactyl","html_url":"https://github.com/kimadactyl","followers_url":"https://api.github.com/users/kimadactyl/followers","following_url":"https://api.github.com/users/kimadactyl/following{/other_user}","gists_url":"https://api.github.com/users/kimadactyl/gists{/gist_id}","starred_url":"https://api.github.com/users/kimadactyl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kimadactyl/subscriptions","organizations_url":"https://api.github.com/users/kimadactyl/orgs","repos_url":"https://api.github.com/users/kimadactyl/repos","events_url":"https://api.github.com/users/kimadactyl/events{/privacy}","received_events_url":"https://api.github.com/users/kimadactyl/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-06-21T11:24:33Z","updated_at":"2016-06-21T14:07:02Z","closed_at":null,"body":"Heya, a bit hard to explain! Apols if this doesn't really get it.\r\n\r\nI have members, locations, and member_locations - i.e., people live at addresses to and from certain dates. Members have_many locations :through member_locations, so I'm basically with the tutorial in theory.\r\n\r\nMy problem comes when I want to add a new location rather than attaching an existing one. When I do this, the last location added edits to become the new one: i.e, it's not making a new record but updating the current one. Everything else is working as expected, not added any JS yet so it's ugly but basically working.\r\n\r\nAny ideas? Can take some screenshots if that helps.\r\n\r\nMy form:\r\n```ruby\r\n<%= semantic_form_for(member) do |f| %>\r\n  <%= f.inputs do %>\r\n    <div id=\"tasks\">\r\n      <%= f.semantic_fields_for :member_locations do |member_location| %>\r\n        <%= render 'member_location_fields', f: member_location %>\r\n      <% end %>\r\n      <div class=\"links\">\r\n        <p>\r\n          <%= link_to_add_association 'add existing location', f, :member_locations %>\r\n        </p>\r\n      </div>\r\n    </div>\r\n  <% end %>\r\n  <%= f.actions do %>\r\n    <%= f.action :submit, :as => :button %>\r\n  <% end %>\r\n<% end %>\r\n```\r\n\r\n_member_location_fields.html.erb\r\n```ruby\r\n<div class=\"nested-fields member-location-fields\">\r\n  <%= f.inputs do %>\r\n    <div id=\"location-from-list\">\r\n      <%= f.input :location, :collection => Location.order('name ASC').all, :prompt => 'Choose an existing location' %>\r\n      <%= f.input :from, :as => :date_picker %>\r\n      <%= f.input :to, :as => :date_picker %>\r\n    </div>\r\n    <%= link_to_add_association 'create a new location', f, :location %>\r\n    <%= link_to_remove_association \"remove location\", f %>\r\n  <% end %>\r\n</div>\r\n```\r\n\r\n_location_fields.html.erb\r\n```ruby\r\n<div class=\"nested-fields\">\r\n  <%= f.inputs do %>\r\n    <%= f.input :name %>\r\n    <%= f.input :line1 %>\r\n    <%= f.input :line2  %>\r\n    <%= f.input :city %>\r\n    <%= f.input :postcode %>\r\n  <% end %>\r\n</div>\r\n```"},"comment":{"url":"https://api.github.com/repos/nathanvda/cocoon/issues/comments/227450610","html_url":"https://github.com/nathanvda/cocoon/issues/372#issuecomment-227450610","issue_url":"https://api.github.com/repos/nathanvda/cocoon/issues/372","id":227450610,"user":{"login":"nathanvda","id":34460,"avatar_url":"https://avatars.githubusercontent.com/u/34460?v=3","gravatar_id":"","url":"https://api.github.com/users/nathanvda","html_url":"https://github.com/nathanvda","followers_url":"https://api.github.com/users/nathanvda/followers","following_url":"https://api.github.com/users/nathanvda/following{/other_user}","gists_url":"https://api.github.com/users/nathanvda/gists{/gist_id}","starred_url":"https://api.github.com/users/nathanvda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nathanvda/subscriptions","organizations_url":"https://api.github.com/users/nathanvda/orgs","repos_url":"https://api.github.com/users/nathanvda/repos","events_url":"https://api.github.com/users/nathanvda/events{/privacy}","received_events_url":"https://api.github.com/users/nathanvda/received_events","type":"User","site_admin":false},"created_at":"2016-06-21T14:07:02Z","updated_at":"2016-06-21T14:07:02Z","body":"Well, now you post both a `location_id` and the `location` contents, which seems to cause (from the logging) to overwrite the old location (as you said). So you have to remove the `location_id` from the form, and only when you press the `link_to_add_association` button, and the only way is using js and listening to the `cocoon:after/before-insert` callback. \r\n\r\nIs that clear? \r\n"}}
{"actor":{"display_login":"nathanvda"}}