Link_to href和文本混淆

时间:2016-10-20 15:07:10

标签: ruby-on-rails

我有一个页面的文档下载功能。这是代码

%td= link_to upload.file, '#', class: " bogus btn btn-xs #{'btn-primary' if upload.published}"

问题在于产生以下html:

<a href="#" class=" bogus btn btn-xs btn-primary" data-original-title="" title="">/public/uploads/file/46/random.txt</a>

我认为这就像将结构改为此一样简单:

%td= link_to '#', upload.file, class: " bogus btn btn-xs #{'btn-primary' if upload.published}"

会导致以下html:

<a href="/public/uploads/file/46/random.txt" class=" bogus btn btn-xs btn-primary" data-original-title="" title="">#</a>

然而,这会导致以下错误:

undefined method `model_name' for FileUploader:Class

1 个答案:

答案 0 :(得分:0)

你可以试试这样的事情<%= link_to "#", upload.file.url, class: " bogus btn btn-xs #{'btn-primary' if upload.published}" %>