V
V
Vayladion Gognazdiak2014-07-18 10:48:39
Ruby on Rails
Vayladion Gognazdiak, 2014-07-18 10:48:39

Why does the condition fail?

There is:
application.html.erb
<% if !current_page? (root_path || regulation_path || test_path || device_path) %>
<% else %>
<%= render 'banner' %>
<% end -%>

rake routes
root GET /(:locale)(.:format) welcome# test
regulation GET (/:locale)/regulation(.:format) welcome#regulation
test GET (/:locale)/test(.:format) welcome#test
device GET (/:locale)/device(.:format) welcome #device

Required not to render banner on all pages except regulation, test , device.
Login to / ( root ) and /regulation does not display the banner. But when logging into /test and /device it shows up.
What is the reason for this behavior of rails?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
_
_ _, 2014-07-18
@etspring

The behavior is not rails, but ruby.
What is the meaning of:
?
root_path || regulation_path || test_path || device_path - this expression will return the value of the first variable whose value is not nil. Hence current_page? it always works for you with the root_path value. Why it returns true for PATH_INFO / regulation when checking root_path is another question. First you need to "fix it at the conservatory"

@
@proffard, 2014-07-22
_

Try this code:

<%= render 'banner' unless current_page.in? [root_path, regulation_path, test_path, device_path] %>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question