I'd like to get the current path/route to use in an if statmenent in one of my views.
For example, I'd like to achieve something like this:
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
This way, two routes go to the same view, but if accessed via /hello
, it will render an extra partial _hello.erb
onto the view.
Is this possible in Sinatra? What's the best way to achieve it?
I believe you are going to want to use the request
object. request.path_info
should give you what you are looking for.
http://www.sinatrarb.com/faq.html#path_info
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With