【发布时间】:2016-06-04 16:27:08
【问题描述】:
我想在我的一个视图中获取当前路径/路线以在 if 语句中使用。
例如,我想实现这样的目标:
example.erb:
<h4>Foobar<h4>
<p>foo bar foo bar foo bar</p>
<% if current_route == /hello %>
<%= erb :_hello %>
<% end %>
app.rb:
get '/foobar' do
erb :example
end
get '/hello' do
erb :example
end
这样,两条路由会进入同一个视图,但如果通过/hello 访问,它会将额外的部分_hello.erb 渲染到视图上。
这在 Sinatra 中可行吗?实现它的最佳方法是什么?
【问题讨论】: