Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 在rails中呈现HTML文件_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails 3 在rails中呈现HTML文件

Ruby on rails 3 在rails中呈现HTML文件,ruby-on-rails-3,Ruby On Rails 3,我使用CarrierWave将静态HTML模板上传到我网页上的某些用户配置文件 我试图在用户登录后在其主页上呈现HTML文件。上载后HTML文件的路径为: /上传/profile/curation/8/User_Content.html 我是rails的新手,我想我可以 <%= render /uploads/profile/curation/8/User_Content.html %> 获取要呈现的html,但我想这只适用于部分,而不是 有什么建议吗?在控制器中,您可以重定向到所

我使用CarrierWave将静态HTML模板上传到我网页上的某些用户配置文件

我试图在用户登录后在其主页上呈现HTML文件。上载后HTML文件的路径为:

/上传/profile/curation/8/User_Content.html

我是rails的新手,我想我可以

<%= render /uploads/profile/curation/8/User_Content.html %>
获取要呈现的html,但我想这只适用于部分,而不是


有什么建议吗?

在控制器中,您可以重定向到所需页面:

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

可以使用“渲染到字符串”。请看这里

是否有可能只获得上传的html,并将其呈现在我当前所在的页面上?与profiles/8类似,如果您将其读入字符串@myhtml=File。在控制器中打开“full\u path\u to\u File”,您可以使用在视图中输出它。raw是必需的,这样标记就不会被清除。确保您信任正在显示的HTML!好主意我做了以下工作,html存储在collumn name curation下,但它表示该文件不存在。。。我检查了我的rails应用程序文件夹,它是/public/uploads/profile/curation/8/User_Content.html,看起来确实在那里。我需要在它之前包含public吗?好的,再更新一次,我得到了file.open,不会给我一个错误,但是它会返回文件的内存位置,而不是文件本身的内容。输出类似于建议?您需要在控制器中加载文件,而不是在视图中加载文件。阅读File.open的语法。在注释中很难做到简洁。嗯,好吧,那么在我的配置文件控制器中,我添加了@myhtml=render_to_string:file=>@profile.curation.to_s,然后在我的show.html.erb视图中添加了,但仍然没有显示任何内容……我还需要做些什么来正确渲染它吗?另外,这些语句不是字符串…我只需要在它们周围键入引号,这样我就可以发布注释:非常抱歉,我太笨了,把它放在了错误的控制器中。。。该错误实际上发生在@myhtml=render_to_string:file=>@profile.curation.to_s,表示该文件缺少模板。有什么想法吗?如果我导航到localhost:3000/uploads/profile/curation/8/User\u Content.html,我就能看到我上传的html…Idk,如果这些信息有帮助的话,但我希望有帮助。试试这个render\u to\u字符串:file=>/uploads/profile/curation/8/User\u Content.html,:layout=>nil.html\u safe