Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File input for paperclip #999

Closed
vladislavbakan opened this issue Feb 24, 2014 · 9 comments · Fixed by #1007
Closed

File input for paperclip #999

vladislavbakan opened this issue Feb 24, 2014 · 9 comments · Fixed by #1007

Comments

@vladislavbakan
Copy link

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
Copy link

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)>'

@justinfrench
Copy link
Member

@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
Copy link
Member

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

@derekprior
Copy link

@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
Copy link

@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
Copy link
Member

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

@mindhalt
Copy link

mindhalt commented Mar 6, 2014

I have same problem 😢 Any progress on this issue?

aennchen added a commit to aennchen/formtastic that referenced this issue Mar 11, 2014
makes paperclip upload work
fixes formtastic#999
@justinfrench
Copy link
Member

@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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants