2010-06-02 4 views
0

Tree Based Navigation과 같은 탐색을 구현하려고하지만 routes.rb (경로, 자원 등 ...)에 정의 된 URL을 기반으로합니다.라우팅을 기반으로 선택 만들기?

routes.rb에 정의 된 모든 경로의 컬렉션을 검색 할 수 있습니까?

그래서 나는이 같은 선택에 사용할 수 있습니다 :

<%= f.collection_select :url, Route.all, :url, :name %> 

TNX을!

답변

0

고스트에 대한 고비용 David Lyod 해결했습니다! 여기

내 코드입니다 :

도우미-방법

# Methods added to this helper will be available to all templates in the application. 
module ApplicationHelper 

    def routes_url 
    routes = ActionController::Routing::Routes.routes.collect do |route| 
     segs = route.segments.inject("") { |str,s| str << s.to_s } 
     segs.chop! if segs.length > 1 
     segs.chomp("(.:format)") 
    end 
    routes.delete_if {|x| x.index(':id')} 
    return routes.compact.uniq.sort 
    end 
end 

내보기에 내가 넣어 :

<%= select("page", "url", options_for_select(routes_url), {:include_blank => true}) %> 
1
ActionController::Routing::Routes.routes 

사용 가능한 경로를 나열합니다. 적용 가능한 세부 사항을 추출하기 위해 일부 구문 분석이 필요합니다.

관련 문제