Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/58.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 ';或';和'||';-在这种情况下要求x或y?_Ruby On Rails - Fatal编程技术网

Ruby on rails ';或';和'||';-在这种情况下要求x或y?

Ruby on rails ';或';和'||';-在这种情况下要求x或y?,ruby-on-rails,Ruby On Rails,我在application.html.erb ... <body> <div class="container"> <%= render 'layouts/header' %> <section class="<%= "login_section" if login_or_signup? %>"> #here's the issue <% flash.each do |key, value|

我在
application.html.erb

...
<body>
  <div class="container">
    <%= render 'layouts/header' %>
      <section class="<%= "login_section" if login_or_signup? %>"> #here's the issue
        <% flash.each do |key, value| %>
          <div class="flash <%= key %>"><%= value %></div>
        <% end %>
        <%= yield %>
      </section>
    <%= render 'layouts/footer' %>
  </div>
</body>
...
我也尝试过像
login\u path或signup\u path
(login\u path | signup\u path)
,和
(login\u path或signup\u path)
,但它们都不会正确地计算为
true
/login
/signup>。我试着把它写成

def login_or_signup?
  request.path == login_path
end
这是意料之中的事

怎么样

def login_or_signup?
  current_page?(:login) || current_page?(:signup)
end

怎么样

def login_or_signup?
  current_page?(:login) || current_page?(:signup)
end

你应该换一种想法:
[login\u path,signup\u path].include?(request.path)
-但是我不确定它会对URL中的GET参数和额外内容做出什么反应你的语句
request.path==login\u path | signup\u path
是错误的。通过这种方式,您可以将
request.path
login_path | | signup_path
的结果进行比较,结果总是正确的。这就像
request.path==true
一样,它也总是返回true。这是不正确的。一开始我也这么认为,但实际上如果
request.path==login\u path | | signup\u path
返回
true
,如果
request.path==login\u path
则返回
/signup
。相等性在析取之前求值。至少在ruby 2.0中。另外,
login_path | | signup_path
的计算结果无论如何都是字符串,而不是布尔值。实际上你是对的。你应该换一种方式来考虑:
[login_path,signup_path]。include?(request.path)
-但我不确定它将如何处理URL中的GET参数和额外内容您的语句
request.path==login_path | | signup_path
是错误的。通过这种方式,您可以将
request.path
login_path | | signup_path
的结果进行比较,结果总是正确的。这就像
request.path==true
一样,它也总是返回true。这是不正确的。一开始我也这么认为,但实际上如果
request.path==login\u path | | signup\u path
返回
true
,如果
request.path==login\u path
则返回
/signup
。相等性在析取之前求值。至少在ruby 2.0中。另外,
login_path | | signup_path
的计算结果无论如何都是字符串,而不是布尔值。实际上你是对的。