2013-05-26 31 views
3

我想使用Rails中的引導框架將PDF鏈接到按鈕。例如,按鈕會說現在下載並鏈接到PDF。我不關心PDF如何打開,只是它與它鏈接。使用Bootstrap將按鈕鏈接到PDF文件

在Bootstrap文檔中,它說只使用<a>標籤,並沒有提及任何有關<%= link_to %>標籤的內容。這就是Bootstrap文檔的<a class="btn btn-large btn-danger" href="#">Download Now</a>中列出的內容,其中「立即下載」是按鈕上的文本顯示。

任何幫助表示讚賞。

+0

它只是作爲普通的論據之一。用您的pdf文檔路徑替換#的href =「#」。 – happy

+2

你只是建立一個這樣的鏈接:'<%= link_to download_path,:class =>「btn btn-large btn-danger」do%>立即下載<% end %>' –

回答

4

可以指定類作爲的link_to

<%= link_to "Download Now", '/path/to/file/or/path_method', :class => "btn btn-large btn-danger" %> 

<%= link_to '/path/to/file/or/path_method', :class => "btn btn-large btn-danger" do %> 
    Download Now 
<% end %> 

Rails Framework Documentation for link_to

+0

當我這樣做時,我得到'沒有路由匹配[GET ]「/images/Products.pdf」。我想我需要爲這個文件定義一個路由,但我不確定使用這個路徑的確切語法。正如你可以告訴該文件被稱爲Products.pdf,我已經在我的/ assets/images/foler – mcadamsjustin

+1

嘗試asset_path('images/Products.pdf')而不是直線路徑 –

+0

我仍然得到相同的錯誤 – mcadamsjustin