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

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

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

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

sobrinho opened this issue Aug 18, 2009 · 6 comments

Comments

@sobrinho
Copy link

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

jaycode commented Dec 10, 2009

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

@sobrinho
Copy link
Author

Thanks jaycode,

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

Thanks again

@jaycode
Copy link
Contributor

jaycode commented Dec 11, 2009

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

@jaycode
Copy link
Contributor

jaycode commented Dec 11, 2009

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

@sobrinho
Copy link
Author

Thanks again jaycode ;)

@ghost
Copy link

ghost commented Dec 12, 2009

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

nglx pushed a commit that referenced this issue Apr 12, 2016
This issue was closed.
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

No branches or pull requests

2 participants