【问题标题】:Why is current_page? returning false when I am passing it my current path?为什么是 current_page?当我通过当前路径时返回false?
【发布时间】:2017-01-16 18:39:14
【问题描述】:

我正在使用 current_page?像这样的帮助文件中的方法:

if current_page?("users/#{user.id}/posts") || current_page?("users/#{user.id}")

当我的路径与传递给第二个 current_page 的参数相同时,它是错误的吗?打电话

这是我当前页面的网址:

http://localhost:3000/users/3

user.id == 3 现在

我打开了更好的错误调试器,这是一些 current_page 的结果?调用:

current_page?(controller: "users") == false


current_page?(action: "show") == true

current_page?("users/3") == false

current_page? "http://localhost:3000/users/3" == true

为什么是current_page?方法对我的相对路径失败?

我不想在它前面加上 localhost:3000,因为那样方法调用只会在开发中为真。

感谢您的帮助。

【问题讨论】:

    标签: ruby-on-rails


    【解决方案1】:

    尝试放置相对路径,如下所示:

     if current_page?("/users/#{user.id}/posts") || current_page?("/users/#{user.id}"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-14
      • 2011-05-22
      • 1970-01-01
      • 2021-02-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多