has_attached_file :image... paperclip image attachment
f.input :image, :as => :file throws error (wrong argument)
f.input :image, :required => false, :as => :file resolves issue
f.input :image, :as => :file
f.input :image, :required => false, :as => :file
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:
f.input :image, as: file
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)>'
@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.
cc @vladislavbakan too — need some help to understand what needs to change in Formtastic (if anything).
@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
@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.
@derekprior you're so close, any chance of starting a patch or pull request? :)
I have same problem 😢 Any progress on this issue?
check arity of validator conditionals
makes paperclip upload work
@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.
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.
Install formtastic from git master to fix issues with rails 4