我需要一個快速提示,看起來很簡單。我有一些私人文件夾內的圖片,並希望在我的視圖中顯示它們。如何從視圖內的私人文件夾中顯示圖像?
我發現的唯一的解決辦法是這樣的:
def show
send_file 'some/image/url', :disposition => 'inline', :type => 'image/jpg', :x_sendfile => true
end
我讀過:disposition => 'inline'
不應觸發圖像下載,讓我來顯示它在我的視圖中。問題是,每次我觸發show
操作時,圖像下載都會自動激活並自動下載。不顯示show
操作的視圖。
如何在View中顯示該圖像?謝謝。
我有一個'send_file'some/path /#{params [:image]}。jpg「,:disposition =>'inline'的方法, :type =>'image/jpg',:x_sendfile = > true'不通過。 Ma圖像源始終設置在'/ images /:image'上,而不是在我爲'send_file'指定的路徑上。所以它在'show.html.erb'視圖的url上設置。 – user3339562
我會爲你加入一個工作示例。看我的編輯。 –
您應該調用renderpic_path(「filename.jpg」)或「/images/filename.jpg」以使其工作。 –