{"action":"created","issue":{"url":"https://api.github.com/repos/elabs/refile/issues/120","labels_url":"https://api.github.com/repos/elabs/refile/issues/120/labels{/name}","comments_url":"https://api.github.com/repos/elabs/refile/issues/120/comments","events_url":"https://api.github.com/repos/elabs/refile/issues/120/events","html_url":"https://github.com/elabs/refile/issues/120","id":54675347,"number":120,"title":"Upload via form in rails 4.2","user":{"login":"dg-ratiodata","id":1267524,"avatar_url":"https://avatars.githubusercontent.com/u/1267524?v=3","gravatar_id":"","url":"https://api.github.com/users/dg-ratiodata","html_url":"https://github.com/dg-ratiodata","followers_url":"https://api.github.com/users/dg-ratiodata/followers","following_url":"https://api.github.com/users/dg-ratiodata/following{/other_user}","gists_url":"https://api.github.com/users/dg-ratiodata/gists{/gist_id}","starred_url":"https://api.github.com/users/dg-ratiodata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dg-ratiodata/subscriptions","organizations_url":"https://api.github.com/users/dg-ratiodata/orgs","repos_url":"https://api.github.com/users/dg-ratiodata/repos","events_url":"https://api.github.com/users/dg-ratiodata/events{/privacy}","received_events_url":"https://api.github.com/users/dg-ratiodata/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-01-17T21:10:35Z","updated_at":"2015-01-21T13:17:07Z","closed_at":null,"body":"I'm using the following software\r\n\r\n```bash\r\n[git:master]% bundle show refile\r\n/home/user/.gem/ruby/2.2.0/gems/refile-0.5.0\r\n[git:master]% bundle show rails\r\n/home/user/.gem/ruby/2.2.0/gems/rails-4.2.0\r\n```\r\n\r\nThis is my model\r\n\r\n```ruby\r\nclass ValidationJob < ActiveRecord::Base\r\n[...]\r\n  attachment :source_file\r\n[...]\r\nend\r\n```\r\n\r\nI'm uploading the file using the form below\r\n\r\n```haml\r\n= form_for(@validation_job, html: { class: 'fe-form' }) do |f|\r\n  - if @validation_job.errors.any?\r\n    = render partial:'errors/saved_object', object: @validation_job\r\n\r\n  .fe-form-field\r\n    = f.attachment_field :source_file, class: 'fe-form-file-field'\r\n  .fe-form-field\r\n    = f.submit t('views.validation_jobs.new.link'), class: 'fe-button-new'\r\n```\r\n\r\nThe params hash contains this:\r\n\r\n```pry\r\n[21] pry(#<ValidationJobsController>)> params['validation_job']['source_file']\r\n=> #<ActionDispatch::Http::UploadedFile:0x000000041f8a98\r\n@content_type=\"application/zip\",\r\n@headers=\"Content-Disposition: form-data; name=\\\"validation_job[source_file]\\\"; filename=\\\"blub.zip\\\"\\r\\nContent-Type: application/zip\\r\\n\",\r\n@original_filename=\"blub.zip\",\r\n@tempfile=#<File:/tmp/RackMultipart20150117-25550-28gxif.zip>>\r\n```\r\n\r\nWhen adding this to source_file\r\n```pry\r\n@validation_job.source_file = params['validation_job']['source_file']\r\n```\r\n\r\nThis is the attachment after adding the file from from.\r\n\r\n```pry\r\n[29] pry(#<ValidationJobsController>)> @validation_job.source_file = params['validation_job']['source_file']\r\n=> #<ActionDispatch::Http::UploadedFile:0x000000041f8a98\r\n@content_type=\"application/zip\",\r\n@headers=\"Content-Disposition: form-data; name=\\\"validation_job[source_file]\\\"; filename=\\\"blub.zip\\\"\\r\\nContent-Type: application/zip\\r\\n\",\r\n@original_filename=\"blub.zip\",\r\n@tempfile=#<File:/tmp/RackMultipart20150117-25550-28gxif.zip>>\r\n```\r\n\r\nNow I'm gonna save the file.\r\n\r\n```pry\r\n[30] pry(#<ValidationJobsController>)> @validation_job.save!\r\n(0.3ms)  BEGIN\r\nSQL (0.3ms)  UPDATE \"validation_jobs\" SET \"progress\" = $1, \"source_file_id\" = $2, \"updated_at\" = $3 WHERE \"validation_jobs\".\"id\" = $4  [[\"progress\", nil], [\"source_file_id\", \"9456bb331274aca0e0ee66564e918aa18a47034404978ca142a3a2abb2ae\"], [\"updated_at\", \"2015-01-17 21:06:32.903457\"], [\"id\", 9]]\r\n(3.3ms)  COMMIT\r\n=> true\r\n```\r\n\r\nWhat is weird, the size is zero.\r\n\r\n```pry\r\n[25] pry(#<ValidationJobsController>)> @validation_job.source_file.size\r\n=> 0\r\n```\r\n\r\nBut if I use `#tempfile` on `params`, then adding the file works differently.\r\n\r\n```pry\r\n[26] pry(#<ValidationJobsController>)> @validation_job.source_file = params['validation_job']['source_file'].tempfile\r\n=> #<File:/tmp/RackMultipart20150117-25550-28gxif.zip>\r\n```\r\n\r\nNow it shows the correct size.\r\n\r\n```pry\r\n[27] pry(#<ValidationJobsController>)> @validation_job.source_file.size\r\n=> 5754238\r\n```\r\n\r\nAnything I do/did wrong? Thanks a lot.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/elabs/refile/issues/comments/70834611","html_url":"https://github.com/elabs/refile/issues/120#issuecomment-70834611","issue_url":"https://api.github.com/repos/elabs/refile/issues/120","id":70834611,"user":{"login":"jnicklas","id":134,"avatar_url":"https://avatars.githubusercontent.com/u/134?v=3","gravatar_id":"","url":"https://api.github.com/users/jnicklas","html_url":"https://github.com/jnicklas","followers_url":"https://api.github.com/users/jnicklas/followers","following_url":"https://api.github.com/users/jnicklas/following{/other_user}","gists_url":"https://api.github.com/users/jnicklas/gists{/gist_id}","starred_url":"https://api.github.com/users/jnicklas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jnicklas/subscriptions","organizations_url":"https://api.github.com/users/jnicklas/orgs","repos_url":"https://api.github.com/users/jnicklas/repos","events_url":"https://api.github.com/users/jnicklas/events{/privacy}","received_events_url":"https://api.github.com/users/jnicklas/received_events","type":"User","site_admin":false},"created_at":"2015-01-21T13:17:07Z","updated_at":"2015-01-21T13:17:07Z","body":"This is very strange. I have no idea how to help you though. This behaviour is quite well tested, and I can't replicated it locally. The very best would be if you were able to write a failing test case for this (see `spec/refile/feature`). Or failing that, provide an example application which shows off this failure. Try digging a bit deeper, into what the `size` method is doing and where it's going wrong. In pry, doing something like `show-source @validation_job.source_file.size` is a good starting point."}}