2011-09-22 64 views
3

你好我使用High Voltage在铁轨我的静态页面,但我看到了一个结构时,我让我的静态网页:删除网页/网页静态轨道

myserver.com/ /约

myserver.com/ /隐私

myserver.com/ /项 。

我不想那“页”单词出现。我想出现这种结构

myserver.com/about

myserver.com/privacy

myserver.com/terms

非常感谢你。问候!

回答

8

看到this bug

这可能工作:

match '/:id' => 'high_voltage/pages#show', :as => :static, :via => :get 

编辑:

当你使用上面的说明,您还需要经过你的意见,改变的所有实例:

page_path(:id=>:about) 

去:

static_path(:id=>:about)` 

或更好,但刚:

static_path(:about) 

那么找到你的看法所有的link_to的,让上面的改变...您的网址将不再有字在他们

希望这有助于

+0

不要工作:(,我检查这个补丁对我来说,但不工作的罚款我的链接_footer.html.erb具有这种结构 <%=的link_to “关于”,page_path(:ID =>。 “约”)%> 我看到了我的页脚链接但这种结构 myserver.com/pages/about, myserver.com/pages/privacy, myserver.com/pages/terms 谢谢! – hyperrjas

+0

我会更新我的答案更多说明,这是行不通的,我现在正在使用它:) – stephenmurdoch

+0

好吧,我起来约会我的回答。请记住尽可能将路线尽可能靠近routes.rb的底部,这似乎有助于防止其他问题在 – stephenmurdoch

0

这个工作对我来说:

match '*id', :to => 'high_voltage/pages#show' 
2

通过将以下内容添加到config/routes.rb文件中,您可以删除URL的“/ pages”部分。

match '/*id' => 'high_voltage/pages#show', :as => :static, :via => :get 

“*”将允许支持嵌套目录。

然后,您可以创建指向app/views/pages/en/test.html的链接“/ en/test”。erb如下:

<%= link_to "Test", static_path("en/test") %> 

要完成您的半静态设置,您不妨考虑2件事。

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/

0

根据documentation,现在可以通过将以下代码添加到high_voltage初始值设定项来完成此操作。我已经在使用2.4版本的gem的rails 4+中成功地使用了它。

# config/initializers/high_voltage.rb 
HighVoltage.configure do |config| 
    config.route_drawer = HighVoltage::RouteDrawers::Root 
end