加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby – 如何在Sinatra获得当前的路线/路线?

发布时间:2020-12-17 03:56:52 所属栏目:百科 来源:网络整理
导读:我希望在我的一个视图中获取当前路径/路径以用于if statmenent. 例如,我想要实现这样的事情: example.erb: h4Foobarh4pfoo bar foo bar foo bar/p% if current_route == /hello % %= erb :_hello %% end % app.rb: get '/foobar' do erb :exampleendget '
我希望在我的一个视图中获取当前路径/路径以用于if statmenent.

例如,我想要实现这样的事情:

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有可能吗?实现它的最佳方法是什么?

解决方法

我相信你会想要使用请求对象. request.path_info应该给你你想要的东西.

http://www.sinatrarb.com/faq.html#path_info

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读