删除静电页面导轨的高压页面/
您好我在rails中使用High Voltage我的静态页面,但是当我创建静态页面时,我会看到下一个结构:
myserver.com/ pages / about
myserver.com/ pages / privacy
myserver.com/ pages / terms。
。
。
。
我不希望出现“页面”字样。 我希望看起来像这个结构
myserver.com/about
myserver.com/privacy
myserver.com/terms
非常感谢你。 问候!
看到这个bug
这可能有效:
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.rb文件中添加以下内容来删除对URL的“/ pages”部分的需要。
match '/*id' => 'high_voltage/pages#show', :as => :static, :via => :get
“*”将允许支持嵌套目录。
然后,您可以创建指向app / views / pages / en / test.html.erb的链接“/ en / test”,如下所示:
<%= 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初始化程序来完成。 我使用2.4版本的gem在rails 4+中成功使用了它。
# config/initializers/high_voltage.rb HighVoltage.configure do |config| config.route_drawer = HighVoltage::RouteDrawers::Root end