wikis suggested solution to validating remote image url not working

154 views
Skip to first unread message

Adam

unread,
Feb 12, 2012, 1:21:27 AM2/12/12
to carrierwave
Ive tried to implement the custom validation class as per the wiki

https://github.com/jnicklas/carrierwave/wiki/How-to%3a-Validate-the-URL-for-remote-uploads

but it doesnt seem to be working. For invalid urls it raises

OpenURI::HTTPError in CombosController#create

404 Not Found


Carrierwave seems to attempt to fetch the image at the provided url
before any validations are run.

The only way I can see getting round this is to create a virtual
attribute to act as a kind of proxy for the remote_image_url
attribute.

maybe something like this

def remote_image_url_proxy
#code to check the url is valid and resolve goes here
if valid
self.remote_image_url = remote_image_url_proxy
else
errors.add ( .... )
end
end


is there a better way to do this or am i wrong in assuming the wikis
suggestion doesnt work.

Adam

unread,
Feb 26, 2012, 12:18:34 AM2/26/12
to carrierwave
Im a bit confused about validations and carrierwave. In this issue
regarding validating remote urls https://github.com/jnicklas/carrierwave/issues/354
trevorturk suggests using a before_validations filter to clean up urls
and add/remove invalid ones. Then you could do a valiates_persence_of
and if there was no value you could give a nice error.

But I dont understand how this could work as carrierwave attempts to
fetch the image as soon as you set the remote_image_url. The
validations will be run later when you do object.save by which time
its too late.

This is also true of the suggested solution mentioned in my first
post. Whilst the code works, its being called AFTER carrierwave
attempts to fetch it which is too late.

Can anyone confirm this is true? Or am I mistaken?


On Feb 12, 3:21 pm, Adam <adam.akh...@gmail.com> wrote:
> Ive tried to implement the custom validation class as per the wiki
>
> https://github.com/jnicklas/carrierwave/wiki/How-to%3a-Validate-the-U...
Reply all
Reply to author
Forward
0 new messages