2011-08-09 43 views
0

我與我需要能夠與在開始時「#」字符生成URL,像這樣的軌道構建的應用程序的工作:使用Rails單頁的應用程序 - 網址助手

user_path outputs "#/user/1" 
dashboard_url outputs "http://mydomain.com/#/dashboard" 

..等等...

任何想法可能是最好的方式來覆蓋URL助手?

+0

看到http://stackoverflow.com/questions/4275214/get-request-part-after-hash-sign – ghoppe

+0

和http://stackoverflow.com/questions/2612118/action-route-in-路線-rb-in-ruby-on-rails – ghoppe

回答

1

我需要能夠在一開始

爲什麼生成一個「#」字符的URL?服務器在fragment identifier之後將不會看到任何內容。這些URL不會被Rails看到,而且控制器將無法響應它們。

如果您需要創建一個以片段標識符結尾的URL,請使用:anchor

link_to "Comment wall", profile_path(@profile, :anchor => "wall") 
# => <a href="/profiles/1#wall">Comment wall</a> 
+0

服務器不會,但客戶端JavaScript會。 http://orderedlist.com/blog/articles/building-evented-single-page-applications/ –