显示Rails的路由

  def index

    
    unless params[:path].blank?
      @path = params[:path]
      @route = ActionController::Routing::Routes.recognize_path(@path)
    end
    
    @routes = ActionController::Routing::Routes.routes.collect do |route|
      name = ActionController::Routing::Routes.named_routes.routes.index(route).to_s
      verb = route.conditions[:method].to_s.upcase
      segs = route.segments.inject("") { |str,s| str << s.to_s }
      segs.chop! if segs.length > 1
      reqs = route.requirements.empty? ? "" : route.requirements.inspect
      {:name => name, :verb => verb, :segs => segs, :reqs => reqs}
    end



<div style="margin: 10px 0">
  <% form_tag cms_routes_path, :method => :get do %>
    <label>
      Path to Test: <%= text_field_tag :path, @path, :size => 50 %>
    </label>
    <% unless @route.blank? %>
      <div style="margin: 10px 0">
        <%=h @route.inspect %>
      </div>
    <% end %>
  <% end %>
</div>

<table class="data">
  <tr>
    <th class="first"></th>
    <th><div class="dividers">Name</div></th>
    <th><div class="dividers">Verb</div></th>
    <th><div class="dividers">Pattern</div></th>
    <th><div class="dividers">Result</div></th>
    <th class="last"></th>
  </tr>
  <% for route in @routes %><tr>
    <td class="first"></td>
    <td><%=h route[:name] %></td>
    <td><%=h route[:verb] %></td>
    <td><%=h route[:segs] %></td>
    <td><%=h route[:reqs] %></td>
    <td class="last"></td>
  </tr><% end %>
</table>


显示Rails的路由_第1张图片

你可能感兴趣的:(html,cms,Ruby,Rails)