2013-03-04 71 views
1

我正在使用CarrierWave將靜態HTML模板上傳到我的網頁上的某些用戶配置文件。 。在rails中呈現HTML文件

我試圖使用戶的主頁上的HTML文件,一旦他們登錄上載後的HTML文件的路徑爲:

/uploads/profile/curation/8/User_Content.html

我新的軌道,我想我只希望能夠

<%= render /uploads/profile/curation/8/User_Content.html %> 

得到的HTML渲染,但我想這僅適用於諧音,這,這不是。

有什麼建議嗎?

回答

0

您可以使用render_to_string。請看看這裏。 http://russbrooks.com/2009/11/18/embed-a-static-hmtl-page-in-a-rails-view

+0

HMM的確定,所以在我的簡檔控制器I加入 「@myhtml = render_to_string:FILE => @ profile.curation.to_s」 然後在我show.html.erb視圖我加入 「<%= @myhtml% >「 但仍然沒有顯示...有什麼我需要做的正確渲染它?此外,這些陳述不是字符串......我只需要在他們周圍輸入引號,所以我可以發表評論:P – user1582095 2013-03-04 08:23:32

+0

其實對不起,我是愚蠢的,並在錯誤的控制器... 錯誤實際上發生在「 @myhtml = render_to_string:file => @ profile.curation.to_s「這說明文件缺少模板。任何想法? – user1582095 2013-03-04 08:37:46

+0

如果我導航到本地主機:3000/uploads/profile/curation/8/User_Content.html我能夠看到我上傳的HTML ...如果該信息將有所幫助,但我希望它能。 – user1582095 2013-03-04 09:00:55

0

在你的控制器,你可以重定向到你想要的網頁:

redirect_to "/uploads/profile/curation/8/User_Content.html" 
+0

是否可以獲取上傳的html,並將其呈現在我目前所在的頁面上? 喜歡在配置文件/ 8 – user1582095 2013-03-04 07:50:00

+0

如果您在控制器中將它讀入字符串('@myhtml = File.open('full_path_to_file')'),您可以在視圖中使用'<%= raw @myhtml%> '。 'raw'是必需的,這樣標記就不會被消毒。確保您信任您所展示的HTML! – 2013-03-04 07:54:53

+0

好主意!我做了以下(HTML存儲在列名「curation」下) <%@myhtml = File.open(@ profile.curation.to_s)%> 但它表示該文件不存在.. 。我檢查了我的Rails應用程序文件夾,它是「/public/uploads/profile/curation/8/User_Content.html」,它似乎在那裏。 我需要在它之前包含「公共」嗎? – user1582095 2013-03-04 08:03:57