Reputation: 43
I need to get some images by the url.
The urls are like http://img.wallsbay.com/large/2014/05/2665.jpg but 2014 and 2665 are changings.
My controller has this params:
def image_params
params.require(:image).permit(:content, :remote_content_url, :id)
end
And i tried to get image from the url like this:
@image.remote_content_url = 'http://img.wallsbay.com/large/#{:content}/05/#{:id}jpg'
but remote_content_url is undefined method.
Upvotes: 2
Views: 4620
Reputation: 43
I resolve this issue by adding attr_accessor :remote_content_url
into my image model.
Upvotes: 2
Reputation: 1283
The remote_<attr_name>_url
attribute is to upload images by a given URL.
@model.remote_content_url = "http://img.wallsbay.com/large/2014/05/2665.jpg"
@model.save
@model.content_url // => "<upload-dir>/2665.jpg"
Use @model.content_url
to retrieve the url to the uploaded image.
To apply a transformation use @model.content_url(:square)
.
Upvotes: 3
Reputation: 1904
The correct way to get the image URL would be @image.content.url
assuming content
is the attribute you are using for Carrierwave.
Upvotes: 1