2012-10-08 2 views
0

내 carrierwave 모델 객체에 Accesing 뭔가 :, 내가 렌더링 부분이있는 파일 링크를 넣어려고 속성 이름

#Main haml file 
= render :partial => 'file_upload', :locals => {:f => f, :file_download => 'residence_cert'} 
#Inside the partial 
%a{:href => @postulant_info[file_download]} 

그러나 이것은 단지 파일 이름과 링크를하고있다, 파일의 전체 경로가 아닙니다. 그런 다음 @postulant_info[file_download] 그냥 같은 지역으로 = render :partial => 'file_upload', :locals => {:f => f, :file_download => 'residence_cert', :url => @postulant_info.residence_cert.url}을 렌더링에 URL을 넣을 수 있습니다하지 carrierwave 객체를 파일 이름으로 나에게

-logger.debug @postulant_info.residence_cert #this is returning my carrierwave object -> 'DocumentUploader' 
-logger.debug @postulant_info['residence_cert'] #but this one is just returning a String, the DB record with the file name 

하나 개의 솔루션을 문자열을주고있다하지만 난 때 불필요한 "해야"생각 실현 부분 템플릿 안에 속성 이름이 있습니다.
어떤 생각이라도 좋을 것입니다. 사전

답변

0

나는 그것을 달성 할 수 :

%a{:href => @postulant_info.send(file_download)} 
0

감사드립니다 내가 정확히 어떤 문제에 대해 매우 불확실 해요, 당신은 무엇을 달성하고 싶은지,하지만 당신은 다음 부분에서 출력 파일에 대한 링크를 원하는 경우

%a{:href => @postulant_info.residence_cert.url} 

이면 충분합니다. @postulant_info.residence_cert 당신에게 업 로더 (DocumentUploader)의 인스턴스를 제공하고 #url 방법은 당신이 당신의 파셜에 인스턴스 VAR를 사용하지 말아야합니다 그런데 업로드 된 파일

의 전체 URL을 반환하는 유일한 변수는 부분적인 사용한다 그것은 주어진 것입니다. 마침내

+0

하지만 내 문제는 난 템플릿 거 residence_cert' '이외의 다른 속성을 사용한다는 것입니다. 나는 그것을 할 수있는 일반적인 방법이 필요하다. –