Tim Baas
Tim Baas

Reputation: 6185

Rails nested_form_for not working when using file_field

When using nested_form_for and having a file_field in fields_for I get the following error from paperclip:

Paperclip::AdapterRegistry::NoHandlerError in ProjectsController#create

No handler found for "scan.pdf"

This is correct, because the params don't show an #<ActionDispatch::Http::UploadedFile> object, but just the file name.

Before using nested_form_for it worked, it works when I uncomment the file_field and it also works when I build the first object for fields_for but this shouldn't be necessary..

My setup is as follows:

The code:

# @project.schemes.build
= nested_form_for @project do |f|
  = f.fields_for :schemes do |ff|
    = ff.text_field :name
    = ff.file_field :scan

Upvotes: 2

Views: 1237

Answers (1)

lest
lest

Reputation: 8100

The generated form is not multipart and you have 2 options to solve this issue:

  • specify multipart manually

    = nested_form_for @project, :html => { :multipart => true } do |f|
    
  • try using nested_form gem from the master branch which have this issue solved but not yet released

    gem 'nested_form', :github => 'ryanb/nested_form'
    

Upvotes: 2

Related Questions