我想在我的一个视图中获取要在 if statmenent 中使用的当前路径/路由。
例如,我想实现这样的事情:
例子.erb:
<h4>Foobar<h4>
<p>foo bar foo bar foo bar</p>
<% if current_route == /hello %>
<%= erb :_hello %>
<% end %>
应用.rb:
get '/foobar' do
erb :example
end
get '/hello' do
erb :example
end
这样,两条路由将转到同一视图,但如果通过 /hello
访问,它将在视图上呈现额外的部分_hello.erb
。
这在辛纳屈可能吗?实现它的最佳方法是什么?
我相信
你会想要使用request
对象。 request.path_info
应该给你你想要的东西。
http://www.sinatrarb.com/faq.html#path_info