Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 使用属性名访问我的carrierwave模型对象_Ruby On Rails 3_Haml_Carrierwave - Fatal编程技术网

Ruby on rails 3 使用属性名访问我的carrierwave模型对象

Ruby on rails 3 使用属性名访问我的carrierwave模型对象,ruby-on-rails-3,haml,carrierwave,Ruby On Rails 3,Haml,Carrierwave,我正在尝试放置一个带有部分渲染的文件链接,如下所示: #Main haml file = render :partial => 'file_upload', :locals => {:f => f, :file_download => 'residence_cert'} #Inside the partial %a{:href => @postulant_info[file_download]} 但这只是使用文件名而不是文件的完整路径创建链接。然后意识到@post

我正在尝试放置一个带有部分渲染的文件链接,如下所示:

#Main haml file
= render :partial => 'file_upload', :locals => {:f => f, :file_download => 'residence_cert'}
#Inside the partial
%a{:href => @postulant_info[file_download]}
但这只是使用文件名而不是文件的完整路径创建链接。然后意识到
@posturlant\u info[文件下载]
只是给了我一个带有文件名的字符串,而不是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
一种解决方案是将url放在呈现中作为本地的,比如
=render:partial=>'file\u upload',:locals=>{:f=>f,:file\u download=>'residence\u cert',:url=>@postant\u info.residence\u cert.url}
,但我认为当属性名在部分模板中时,“应该”是不必要的。

任何想法都将不胜感激。提前感谢

我非常不确定您的问题到底是什么,以及您试图实现什么,但是如果您想输出指向文件的链接,请在您的部分

%a{:href => @postulant_info.residence_cert.url}
够了
@postatlant\u info.residence\u cert
将为您提供上载程序的实例(
DocumentUploader
),而
#url
方法将返回上载文件的完整url


顺便说一句,您应该避免在分部中使用实例变量,分部应该使用的唯一变量是给定的变量。

最后,我可以通过以下方法实现:

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

但我的问题是,除了
residence\u cert
之外,我还要将模板与其他属性一起使用。我需要一个通用的方法来做这件事