2016-08-22 4 views
0

URL로 일부 이미지를 가져와야합니다.반송파 이미지를 URL로 가져 오기

URL은 http://img.wallsbay.com/large/2014/05/2665.jpg이지만 2014 및 2665는 변경됩니다.

def image_params 
    params.require(:image).permit(:content, :remote_content_url, :id) 
    end 

을 그리고 난 같은 URL에서 이미지를 얻기 위해 노력 :

내 컨트롤러는이 PARAMS이

@image.remote_content_url = 'http://img.wallsbay.com/large/#{:content}/05/#{:id}jpg' 

을하지만 remote_content_url은 정의되지 않은 방법이다.

답변

1

attr_accessor :remote_content_url을 내 이미지 모델에 추가하여이 문제를 해결합니다.

0

이미지 URL을 가져 오는 올바른 방법은 @image.content.url이고, content은 Carrierwave에 사용중인 것으로 가정합니다.

+0

그래, 알고 싶지만 그런 걸 원해. https://github.com/carrierwaveuploader/carrierwave/wiki/How-to:-Upload-remote-image-urls-to-your-seedfile – Salanoid

0

remote_<attr_name>_url 속성은 지정된 URL로 이미지를 업로드하는 것입니다.

@model.remote_content_url = "http://img.wallsbay.com/large/2014/05/2665.jpg" 
@model.save 
@model.content_url // => "<upload-dir>/2665.jpg" 

사용 @model.content_url 업로드 된 이미지에 URL을 검색 할 수 있습니다.

변형을 적용하려면 @model.content_url(:square)을 사용하십시오.

+0

업로드하고 싶다. 하나 이상의 이미지가 있지만 remote_ _url을 사용할 수 없습니다. – Salanoid

+0

Carrierwave는 이와 같이 다중 업로드를 처리하지 않습니다. 당신은 각 이미지에 대한 레코드를 만들어야합니다. 나는 이것을 달성하기 위해 [dropzone.js] (http://www.dropzonejs.com/)를 사용하는 것을 고려할 것이다. – codyeatworld

+0

지금 dropzone.js이 필요하지 않습니다. remote_content_url을 사용해야하지만 정의되지 않았습니다. – Salanoid

관련 문제