views:

264

answers:

1

I have a strange error that came about when I changed my app from mongrel to mod_rails.

My app changes from a two column layout to a three column layout depending on where the user is in the app. My application layout relies on several helpers to put the divs in the right place.

In application_helper.rb:

  def left_column_layouts
   if  params[:controller] == "users" && params[:action] == "show" ||
       params[:controller] == "friendships" && params[:action] == "index" ||
       params[:controller] == "tags" && params[:action] == "index"
       true
   else
       false
   end 
end

I also have similar logic for where the three column layouts.

Then, in my layout file:

    <% if left_column_layouts %>
    <div class="colmask leftmenu">
    <div class="colleft">
  <%= yield %>
    </div>
    </div>
<% elsif three_columns_with_blank_sides %>
<div class="colmask threecol">
<div class="colmid">
<div class="colleft">
    <%= yield %>
<div class="col2">
</div>
<div class="col3">
</div>
</div>
</div>
</div>
<% else #Three column layout %>
    <div class="colmask threecol">
    <div class="colmid">
    <div class="colleft">
<%= yield %>
    </div>
    </div>
    </div>
<% end %>

This worked well until I changed to mod rails. I can't imagine why mod rails would make this part of the app simply not work.

Interesting note: I went to the https parts of my site and the layout was loading without a problem. My server support guys said I should clear the cache but the problem persists.

Any help would be appreciated!

+1  A: 

I know that this is an old post, but just to make sure that others would see it. If I correctly understand what you want, I believe the problem lies in the logic used in your condition.

If you want to display left column when controller:action is users:show or friendships:index or tags:index, your logic condition is incorrect. You need parentheses to correct them.

For example, let's say users is 'A', show is 'B', friendships is 'C', index of friendships is 'D', tags is 'E', and index of tags is 'F'.

Your code represents A && B || C && D || E && F, but I believe what you want is (A && B) || (C && D) || (E && F). Because A && B || C && D || E && F is not equal to (A && B) || (C && D) || (E && F), the method may return incorrect result. To be more clear, let say all params from A to E are true but F is false. Your method will return false which is supposed to be true. That may be the case.

Taywin
Hey Taywin. Thanks for the help! The server did a major upgrade and now the problem is gone. Wierd. I should implement these changes though to make sure it doesn't happen again.
Kenji Crosland
You are welcome.
Taywin