Skip to content

File input for paperclip #999

Closed
vladislavbakan opened this Issue Feb 24, 2014 · 9 comments

5 participants

@vladislavbakan

rails 4
#model
has_attached_file :image... paperclip image attachment
#view
f.input :image, :as => :file throws error (wrong argument)
f.input :image, :required => false, :as => :file resolves issue

@derekprior

I also see this with paperclip 4.1. I presume it has to do with the new required file type validations

The stack trace with f.input :image, as: file is:

ArgumentError - wrong number of arguments (1 for 0):
  formtastic (2.3.0.rc2) lib/formtastic/inputs/base/validations.rb:39:in `validator_relevant?'
  formtastic (2.3.0.rc2) lib/formtastic/inputs/base/validations.rb:27:in `block in validations'
  formtastic (2.3.0.rc2) lib/formtastic/inputs/base/validations.rb:26:in `validations'
  formtastic (2.3.0.rc2) lib/formtastic/inputs/base/validations.rb:129:in `validations?'
  formtastic (2.3.0.rc2) lib/formtastic/inputs/base/validations.rb:136:in `required?'
  formtastic (2.3.0.rc2) lib/formtastic/inputs/base/labelling.rb:25:in `requirement_text_or_proc'
  formtastic (2.3.0.rc2) lib/formtastic/inputs/base/labelling.rb:29:in `requirement_text'
  formtastic (2.3.0.rc2) lib/formtastic/inputs/base/labelling.rb:20:in `label_text'
  formtastic (2.3.0.rc2) lib/formtastic/inputs/base/labelling.rb:9:in `label_html'
  formtastic (2.3.0.rc2) lib/formtastic/inputs/file_input.rb:36:in `block in to_html'
  actionpack (4.0.3) lib/action_view/helpers/capture_helper.rb:38:in `block in capture'
  actionpack (4.0.3) lib/action_view/helpers/capture_helper.rb:200:in `with_output_buffer'
  actionpack (4.0.3) lib/action_view/helpers/capture_helper.rb:38:in `capture'
  formtastic (2.3.0.rc2) lib/formtastic/inputs/base/wrapping.rb:11:in `input_wrapping'
  formtastic (2.3.0.rc2) lib/formtastic/inputs/file_input.rb:35:in `to_html'
  formtastic (2.3.0.rc2) lib/formtastic/helpers/input_helper.rb:241:in `input'
   () Users/derek/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/bundler/gems/active_admin-66de2f86ae1d/lib/active_admin/form_builder.rb:26:in `block in input'
   () Users/derek/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/bundler/gems/active_admin-66de2f86ae1d/lib/active_admin/form_builder.rb:151:in `with_new_form_buffer'
   () Users/derek/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/bundler/gems/active_admin-66de2f86ae1d/lib/active_admin/form_builder.rb:26:in `input'
  app/admin/partners.rb:11:in `block (3 levels) in <top (required)>'
@mberwanger mberwanger referenced this issue in activeadmin/activeadmin Feb 25, 2014
Closed

paperclip 4.1.1 breaks form file upload #2967

@justinfrench
Owner

@derekprior I can buy that this is probably an issue in Formtastic, but can you please confirm that you've set up the model appropriately as per this article? http://robots.thoughtbot.com/prevent-spoofing-with-paperclip

The final nail in the coffin would be proving your model works with paperclip fine without Formtastic, and we could use that working example to figure out what needs to change in Formtastic going forward.

@justinfrench
Owner

cc @vladislavbakan too — need some help to understand what needs to change in Formtastic (if anything).

@derekprior

@justinfrench here's a dead simple reproduction in a stock rails app (the generator used Rails 4.1, but I also get this in 4.0.x), paperclip 4.1.1 and formtastic master: https://github.com/derekprior/formtastic_bug

@derekprior

@justinfrench It looks like the problem is that formtastic is assuming that if there's a conditional on the validation that responds to call there must be an argument. This isn't necessarily the case (paperclip or otherwise). Looks like if this feature is necessary to maintain you'll have to check the arity of the lambda before deciding how to call it.

https://github.com/justinfrench/formtastic/blob/master/lib/formtastic/inputs/base/validations.rb#L39

@justinfrench
Owner

@derekprior you're so close, any chance of starting a patch or pull request? :)

@mindhalt
mindhalt commented Mar 6, 2014

I have same problem 😢 Any progress on this issue?

@aennchen aennchen added a commit to aennchen/formtastic that referenced this issue Mar 11, 2014
@aennchen aennchen check arity of validator conditionals
makes paperclip upload work
fixes justinfrench#999
1e45bf1
@justinfrench
Owner

@mindhalt Pull request #1007 by @aennchen is trying to solve this — you could help by bundling that fork/branch and verifying that it solves your issue.

@septerr
septerr commented Mar 16, 2014

This bit me today. Took a long time to find an answer on StackOverflow mentioning the workaround of using :required. The error message is quite unhelpful.

@djcp djcp referenced this issue in thoughtbot/paperclip Mar 28, 2014
Closed

Issues with formtastic #1497

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.