gpt4 book ai didi

ruby-on-rails - 在 Rails 中处理嵌套静态页面的最佳方式是什么?

转载 作者:数据小太阳 更新时间:2023-10-29 08:33:49 25 4
gpt4 key购买 nike

编辑:抱歉,标题有点不清楚,我想使用“半静态”页面,使用渲染助手和 ruby​​ 变量。 ERB 模板系统等。对不起大家!我的错!

我一直在研究为我正在构建的 Rails 3.1.3 应用程序创建嵌套的半静态页面,但我还没有找到满足我所有需求的答案。有什么想法吗?

我遇到的所有解决方案都是关于创建只是顶级页面,如下所示:

- Site root
--- About (http://wwww.example.com/about)
--- Contact (http://wwww.example.com/contact)
--- Products (http://wwww.example.com/products)
--- Pricing (http://wwww.example.com/pricing

虽然我想做类似的事情

- Site root
--- About (http://wwww.example.com/about)
------ What we do (http://wwww.example.com/about/what-we-do)
------ Another sub-page (http://wwww.example.com/about/another-sub-page)
--- Contact (http://wwww.example.com/contact)
--- Products (http://wwww.example.com/products)
------ Product One (http://wwww.example.com/products/product-one)
------ Product Two (http://wwww.example.com/products/product-two)
--- Pricing (http://wwww.example.com/pricing)

我遇到过为每个页面映射静态 Controller 等解决方案,但这似乎不是一个特别优雅的解决方案。

或者创建一个通用的路由和 Controller 来匹配请求,像这样:

in routes.rb:
map.connect '*path', :controller => 'content', :action => 'show'

in content_controller.rb:
def show
render :action => params[:path].join('/')
end

但这似乎更不优雅,还有其他我想念的方式吗?

最佳答案

is there another way I'm missing?

是的。

您所要做的就是在/public 中根据需要在public 的根目录或目录结构中创建静态页面。

存在于 /public 下路径的物理文件应该覆盖您为动态生成的页面配置的任何路由。

关于ruby-on-rails - 在 Rails 中处理嵌套静态页面的最佳方式是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8643948/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com