我想在我的公共(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/