开发者

Rails: problem with application.html.erb layout file and application_helper.rb

开发者 https://www.devze.com 2022-12-26 07:48 出处:网络
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

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开发者_JAVA百科_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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消