Skip to content
This repository has been archived by the owner on Jul 17, 2018. It is now read-only.

Reset remote_url field #2

Open
cristi-badila opened this issue Oct 4, 2013 · 0 comments
Open

Reset remote_url field #2

cristi-badila opened this issue Oct 4, 2013 · 0 comments

Comments

@cristi-badila
Copy link

Hello, I just started using your gem recently and it fits perfectly with what i was trying to accomplish on a project but I encountered the following small issue:
I have a form for a model which has some validation rules on it and a paperclip attachment. I then try to show the form for a model instance that has the paperclip attachment's remote_url attribute pre-populated with an image url. When trying to submit the form if the data from the form is valid, everything is ok and the image is saved; however if the validation rules are broken the remote_url attribute is now empty and I would have to do some weird stuff to get it back again. I tracked down this behavior to line 44 in the remote.rb file which looks like this:

      record.send(:"#{name}_remote_url=", nil) # Reset!

It's obvious that somebody thought that it was required to reset the field, but I don't understand why. Is there any reason for this behavior or can it simply be removed? Thanks for the nice work!

Edit:
I tried forking the repository an removing the line myself and I can see that some specs fail by going into a stack overflow but I don't quite understand why. Can you maybe share some light on why this is required?

Second edit:
Looking at the code more carefully I realized that on line 45 another validation sequence is triggered and if the attribute would still be present, an infinite recursion would occur. Still would like to find a way around this so I'm gonna poke around some more.

Last edit:
Fixed this for myself by using an extra instance variable to track if the original attribute was updated. If you consider this is ok I can make a pull request.

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

No branches or pull requests

1 participant