{"action":"created","issue":{"url":"https://api.github.com/repos/refile/refile/issues/300","labels_url":"https://api.github.com/repos/refile/refile/issues/300/labels{/name}","comments_url":"https://api.github.com/repos/refile/refile/issues/300/comments","events_url":"https://api.github.com/repos/refile/refile/issues/300/events","html_url":"https://github.com/refile/refile/issues/300","id":95265717,"number":300,"title":"accepts_nested_attributes_for does not know when to create an image","user":{"login":"yaroslav","id":4277,"avatar_url":"https://avatars.githubusercontent.com/u/4277?v=3","gravatar_id":"","url":"https://api.github.com/users/yaroslav","html_url":"https://github.com/yaroslav","followers_url":"https://api.github.com/users/yaroslav/followers","following_url":"https://api.github.com/users/yaroslav/following{/other_user}","gists_url":"https://api.github.com/users/yaroslav/gists{/gist_id}","starred_url":"https://api.github.com/users/yaroslav/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yaroslav/subscriptions","organizations_url":"https://api.github.com/users/yaroslav/orgs","repos_url":"https://api.github.com/users/yaroslav/repos","events_url":"https://api.github.com/users/yaroslav/events{/privacy}","received_events_url":"https://api.github.com/users/yaroslav/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-15T18:59:32Z","updated_at":"2015-07-15T19:03:06Z","closed_at":null,"body":"Not sure if it's a feature request or just some sort of misconfiguration.\r\n\r\nI have to use a `Entity has_one Image` schema in my project. Normally, that would be a multiple images upload — just as you have in the `README`, but I have to use `has_one`. \r\n\r\nSo initially I had to pass `accepts_nested_attributes_for` something like this:\r\n\r\n```ruby\r\naccepts_nested_attributes_for :photo, allow_destroy: true,\r\n  reject_if: lambda { |attributes| attributes['image'].empty? }\r\n```\r\n\r\nHowever, that does not really work. The way controller passes the params is something like this:\r\n\r\n```\r\n... \"photo_attributes\"=>{\"image\"=>\"null\", \"remote_image_url\"=>\"\", \"_destroy\"=>\"0\" ..\r\n```\r\n\r\non updates, or just\r\n\r\n```\r\n... \"photo_attributes\"=>{\"image\"=>\"null\"} ..\r\n```\r\n\r\nOn new records. Naturally, `image` is not `blank`, so ActiveRecord tries to create a Photo with an empty image.\r\n\r\n`\"null\"` is there because of an input with `data-reference` which is generated by the refile helper, and it seems that it does not matter if I use direct uploads or not. Not sure if this is all by design, but I've ended up with doing this:\r\n\r\n```ruby\r\n  accepts_nested_attributes_for :photo, allow_destroy: true,\r\n    reject_if: lambda { |attributes| Photo.empty_attributes?(attributes) }\r\n```\r\n\r\n```ruby\r\n  def self.empty_attributes?(parameters)\r\n    (parameters[:image].blank? || parameters[:image] == \"null\") &&\r\n      parameters[:remote_image_url].blank?\r\n  end\r\n```\r\n\r\nAm I wrong/misunderstanding the design somewhere or is there a room for improvement?"},"comment":{"url":"https://api.github.com/repos/refile/refile/issues/comments/121714422","html_url":"https://github.com/refile/refile/issues/300#issuecomment-121714422","issue_url":"https://api.github.com/repos/refile/refile/issues/300","id":121714422,"user":{"login":"yaroslav","id":4277,"avatar_url":"https://avatars.githubusercontent.com/u/4277?v=3","gravatar_id":"","url":"https://api.github.com/users/yaroslav","html_url":"https://github.com/yaroslav","followers_url":"https://api.github.com/users/yaroslav/followers","following_url":"https://api.github.com/users/yaroslav/following{/other_user}","gists_url":"https://api.github.com/users/yaroslav/gists{/gist_id}","starred_url":"https://api.github.com/users/yaroslav/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yaroslav/subscriptions","organizations_url":"https://api.github.com/users/yaroslav/orgs","repos_url":"https://api.github.com/users/yaroslav/repos","events_url":"https://api.github.com/users/yaroslav/events{/privacy}","received_events_url":"https://api.github.com/users/yaroslav/received_events","type":"User","site_admin":false},"created_at":"2015-07-15T19:03:06Z","updated_at":"2015-07-15T19:03:06Z","body":"Oh, sorry, refile master (0dc2072a90), Rails 4.2.3"}}