Pra*_*ava 1 render file ruby-on-rails-4
我的内容非常大,我不希望我的 html.erb 文件看起来很糟糕,因为它充满了文本。我知道在 Java 中我们可以做到这一点,但我对 Rails 还很陌生,因此我不能做到这一点。
另外,是否有命令或方法可以返回文件路径。
小智 5
在你的控制器中,执行
@data = File.read("path/to/file.txt")
Run Code Online (Sandbox Code Playgroud)
在你看来(html.erb),
<%= @data %>
Run Code Online (Sandbox Code Playgroud)
或者
在你看来(html.erb),做
<%= File.read("path/to/file.txt") %>
Run Code Online (Sandbox Code Playgroud)
类似问题:Rails如何查看txt文件?