I am a newbie Ruby user and I hesitate on the correct writing of this part:
<% if session[:user_id].nil? || (params[:controller] != 'home' && params[:action] != 'index') %>
something
<% else %>
something else
<% end %>
But the first part of the IF construct is wrong (especially the params part). If I tried this:
<% if params[:controller] != 'home' && params[:action] != 'index' %>
So I got a bad results, but if this:
<% unless params[:controller] == 'home' && params[:action] == 'index' %>
So now I got already a good results…
Where could be a problem? What could be a wrong? The first code is what I need, but I don’t know, how to join everything….
A != B AND C != Dis NOT the same thing as!(A == B AND C == D)The first is true only when BOTH pairs are different. The second is true if EITHER pair is different. In your example, to convert the unless to an if you would do:
So that the condition is true if EITHER don’t match.
Read up on it here
http://en.wikipedia.org/wiki/Logical_connective