Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails,当前页面?(用户路径)给出错误_Ruby On Rails_Ruby - Fatal编程技术网

Ruby on rails Rails,当前页面?(用户路径)给出错误

Ruby on rails Rails,当前页面?(用户路径)给出错误,ruby-on-rails,ruby,Ruby On Rails,Ruby,我想在特定页面上隐藏元素,例如位于app/views/users/(在那里我有new.html.erb;edit.html.erb;show.html.erb。我的布局/application.html.erb中有div,它将显示在所有页面上,所以我想隐藏它 我想我可以这样做: <% unless current_page?(new_user_path) || current_page?(user_path) %> <div>Some content</div&

我想在特定页面上隐藏元素,例如位于
app/views/users/
(在那里我有
new.html.erb
edit.html.erb
show.html.erb
。我的
布局/application.html.erb
中有div,它将显示在所有页面上,所以我想隐藏它

我想我可以这样做:

<% unless current_page?(new_user_path) || current_page?(user_path) %>
  <div>Some content</div>
<% end %>

一些内容
但这会给我一个非常明显的错误:对于user_show方法,他需要一个用户id,但我们不会访问存在variable
@user
的页面。您能帮我一个忙吗:

  • 有没有可能绕过这个错误?(我不想在每个地方都分配@user变量,也不想列出所有允许的页面)

  • 有没有其他方法可以隐藏特定页面上的元素


  • 不完全确定您想要实现什么,但这就是您如何防止用户不在场的方法:

    unless current_page?(new_user_path) || @user && current_page?(user_path(@user))
    

    不完全确定您想要实现什么,但这就是您如何防止用户不在场的方法:

    unless current_page?(new_user_path) || @user && current_page?(user_path(@user))
    

    我想你可能想要的是:

    <% unless current_page?(controller: 'users') %>
      <div>Some content</div>
    <% end %>
    
    
    一些内容
    
    通过传递
    controller:“用户”
    可以捕获该控制器的所有路由(操作),包括新建/编辑/显示路由


    有关更多详细信息,请参见。

    我想您可能想要的是:

    <% unless current_page?(controller: 'users') %>
      <div>Some content</div>
    <% end %>
    
    
    一些内容
    
    通过传递
    controller:“用户”
    可以捕获该控制器的所有路由(操作),包括新建/编辑/显示路由


    有关更多详细信息,请参见。

    您是否尝试过此操作?如果是,请提供错误详细信息?
    当前页面(用户路径)
    当前页面?(用户路径)
    缺少的
    @Ravi Mariya只是一个打字错误。您尝试过此操作吗?如果是,请提供错误详细信息?
    当前页面(用户路径)
    当前页面?(用户路径)
    一个缺少的
    @Ravi Mariya只是一个输入错误。你明白了。很抱歉,英语不是我的母语,所以一定是我没有用正确的方式告诉我的问题。谢谢你的帮助!请注意,这只适用于节目和新动作,不适用于编辑,因为你必须在
    当前页面(编辑用户路径)中明确包含它(@user))
    你明白了。很抱歉,英语不是我的母语,所以我没有用正确的方式告诉你我的问题。谢谢你的帮助!请注意,这只适用于表演和新动作,不适用于例如编辑,因为你必须在
    当前页面中明确包含它?(编辑用户路径(@user))
    不错,我会记住这一点并可能使用它。谢谢!不错,我会记住这一点并可能使用它。谢谢!