ruby-on-rails - rails : use ruby in public/index

标签 ruby-on-rails public-html

我想在我的公共(public) index.html 中使用 ruby​​(例如,用于样式表或表单)。但我不知道该怎么做 :S

如果我将它重命名为 index.html.erb 或 index.erb,rails 无法识别它。取而代之的是使用我的路由根目录(它是应用程序的一部分,需要用户登录)。

最佳答案

public 目录中的任何内容都呈现为静态 Assets ,因此其中没有 Ruby 代码。

相反,您应该删除该目录中的 index.html 文件,并将其替换为您应用中的其他内容。例如,您可以这样做:

# app/controllers/site_controller.rb
class SiteController < ApplicationController
  def index
    # ...
  end
end

# config/routes.rb
root to: 'site#index'

# app/views/site/index.html.erb
<!-- Your HTML and Ruby here -->

这将为您提供所需的行为。

关于ruby-on-rails - rails : use ruby in public/index,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18485429/

相关文章:

c# - 尝试将文件上传到 Ftp 但收到错误 : "file name not allowed"!

mysql - 制作新的 Rails 应用程序时出错

php - 保护 public_html 中的文件夹

svn - 如何在 Web 服务器上正确设置 SVN?

php - 如何获取 public_html 文件夹的绝对路径?

ruby-on-rails - 如何将图像存储在我的 heroku postgres 数据库中

mysql - Rails Active Record 查询计数多个关系

ruby-on-rails - 我应该将 .Includes() 方法放在 .find() 之前还是之后?

ruby-on-rails - rails 错误的年份 -4712