2012-09-20 77 views
0

我有這樣的問題:我想渲染HTML文件,但我沒有設置路徑到我的文件。如何在渲染文件時設置正確的路徑?

我需要說,我是Windows上的runnung Rails。

在我看來,我有一些代碼:

<%= render :file => '1509/1509/app/views/static_pages/index.html', :layout => false %> 

,但是這給了我錯誤:

undefined method `virtual_path' for false:FalseClass 

我的文件就在這裏:

 C:\1509\1509\app\views\static_pages 

也試過:

<%= render :file => '/views/static_pages/index.html', :layout => false %> 

但是這給了我:

Missing template /views/static_pages/index with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: 
    * "c:/1509/1509/app/views" 
    * "C:/Ruby192/lib/ruby/gems/1.9.1/gems/devise-2.1.0/app/views" 
    * "c:/1509/1509" 
    * "c:/" 

我做錯了嗎?

+0

你做錯了斜槓,因爲我看到,嘗試'\',而不是'/'。 – F0G

+0

嘗試絕對路徑:'render:file =>'C:/ 1509/1509/app/views/static_pages/index.html'。 – gparis

+0

第一個建議給我錯誤#2和secode - 錯誤#1在我的問題。 – MID

回答

1

絕對路徑將是:

<%= render :file => 'c:/1509/1509/app/views/static_pages/index.html' %> 

相對路徑:

<%= render :file => 'static_pages/index.html' %> 
+0

jdoe,謝謝你的回答! – MID

+0

還有一個,當我添加布局爲false時,false'FalseClass'爲未定義的方法虛擬路徑:<%= render:file =>'static_pages/index.html',:layout => false%>'get error:' – MID

+1

@ MID此選項用於控制器內部以覆蓋默認佈局。視圖中的模板無需佈局即可呈現。所以,根本不要使用這個選項。 – jdoe