Remove file doesn't work for has_one association (subforms) #2

Closed
sobrinho opened this Issue Aug 18, 2009 · 6 comments

2 participants

@sobrinho

Hi mnaglick,

I'm having a trouble with your plugin :)

I have a model with has_one association to a model which have paperclip (emulate paperclip_polymorphic plugin). Like that:

class Image < ActiveRecord::Base
  belongs_to :attachable, :polymorphic => true
  has_attached_file :data
end
class News < ActiveRecord::Base
  has_one :image, :as => :attachable
end

So, I created a image controller and a news controller. This works fine.

When I go to create a new news this show a subform with upload, but I needed to set multipart with true on news controller. This can be automatic? I think the file_column_bridge does this.

But the issue is into remove file. When I set to remove file this doesn't remove because name of hidden field name. See the log:

Processing Admin::NewsController#update (for 127.0.0.1 at 2009-08-18 11:16:55) [PUT]
  Parameters: {"commit"=>"Editar", "action"=>"update", "iframe"=>"true", "_method"=>"put", "authenticity_token"=>"elUt0o7Rdv2HlcoEwn3QuPruFtrM/TcbHpOYPIC3nZI=", "id"=>"1", "controller"=>"admin/news", "record"=>{"delete_data"=>"true", "title"=>"Notícia de teste", "content"=>"conteúdo de teste", "summary"=>"resumo de teste", "image"=>{"id"=>"27"}}}

See the delete_data goes to record and not into image hash. See if you can fix this issue and make the automatic multipart for parent controller.

Thanks again mnaglik

@jaycode

change lib/form_ui.rb, line 15 to:
hidden_field("record[#{column.name}]".to_sym, "delete_#{column.name}", :value => "false") +

@sobrinho

Thanks jaycode,

Can you fork and patch the project to request mnaglik pull?

Thanks again

@jaycode

I'll try, never used git before...

@jaycode

just fork-ed it, hey it was easy! (I hope I did it right)

@sobrinho

Thanks again jaycode ;)

@ghost

I've integrated the code to the master branch. Thanks guys!

@managr managr pushed a commit that referenced this issue Apr 12, 2016
@jaycode jaycode Fix for issue #2 58b8ba1
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment