显示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>


[img]http://bot.iteye.com/upload/picture/pic/38388/4847c8cf-339e-353b-b8d8-c260cc760753.jpg[/img]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值