你好,我在rails中使用High Voltage作为静态页面,但是当我制作静态页面时,我看到了下一个结构:
myserver.com/页/关于
myserver.com/页/隐私
myserver.com/页/条款.
.
.
.
我不希望出现"page"这个词。我想让它出现这个结构
myserver.com/about
myserver.com/privacy
myserver.com/terms
非常感谢。的问候!
查看此bug
this may work:
match '/:id' => 'high_voltage/pages#show', :as => :static, :via => :get
编辑:当你使用上面的指令时,你还需要遍历你的视图并更改:
的所有实例page_path(:id=>:about)
:
static_path(:id=>:about)`
或者更好,直接:
static_path(:about)
找到视图中的所有link_to并进行上述更改…您的url将不再包含页面
希望能有所帮助
你可以通过在你的config/routes中添加以下内容来删除URL中需要的"/pages"部分。rb文件。
match '/*id' => 'high_voltage/pages#show', :as => :static, :via => :get
"*"将允许嵌套目录。
然后你可以创建一个链接"/en/test"指向app/views/pages/en/test.html。动词如下:<%= link_to "Test", static_path("en/test") %>
要完成半静态设置,您可能希望考虑另外两件事。
1)目录默认内容的一些基本路由(放在前面的路由行之上)(根据需要)
root :to => 'high_voltage/pages#show', :id => 'index' # map root to 'index.html'
match '/en' => 'high_voltage/pages#show', :id => 'en/test' # map '/en' to '/en/test.html'
2)一个很好的SEO重定向,删除任何额外的尾斜杠:http://nanceskitchen.com/2010/05/19/seo-heroku-ruby-on-rails-and-removing-those-darn-trailing-slashes/
这个适合我:
match '*id', :to => 'high_voltage/pages#show'
根据文档,现在可以通过将下面的代码添加到high_voltage初始化器中来完成。我已经成功地在rails 4+中使用了2.4版本的gem。
# config/initializers/high_voltage.rb
HighVoltage.configure do |config|
config.route_drawer = HighVoltage::RouteDrawers::Root
end