Rails:application.html.erb 布局文件和 application_helper.rb 的问题

发布于 2024-08-28 05:40:19 字数 1396 浏览 3 评论 0原文

当我将应用程序从 mongrel 更改为 mod_rails 时,出现了一个奇怪的错误。

我的应用程序从两列布局更改为三列布局,具体取决于用户在应用程序中的位置。我的应用程序布局依赖于几个助手将 div 放在正确的位置。

在 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

我对于三列布局也有类似的逻辑。

然后,在我的布局文件中:

    <% 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 %>

这一直运行良好,直到我更改为 mod Rails。我无法想象为什么 mod Rails 会让应用程序的这一部分根本无法工作。

有趣的是:我访问了网站的 https 部分,布局加载没有问题。我的服务器支持人员说我应该清除缓存,但问题仍然存在。

任何帮助将不胜感激!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

策马西风 2024-09-04 05:40:19

我知道这是一篇旧帖子,但只是为了确保其他人会看到它。如果我正确理解你想要什么,我相信问题在于你的情况中使用的逻辑。

如果你想在controller:action为users:show或friendships:index或tags:index时显示左栏,你的逻辑条件不正确。您需要括号来纠正它们。

例如,假设用户是“A”,节目是“B”,友谊是“C”,友谊索引是“D”,标签是“E”,标签索引是“F”。

您的代码代表 A &&乙|| C&& D||电子及电子F,但我相信你想要的是 (A && B) || (C&&D)|| (E&F)。因为 A &&乙|| C&& D||电子及电子F 不等于 (A && B) || (C&&D)|| (E && F),该方法可能返回不正确的结果。更清楚地说,假设从 A 到 E 的所有参数都是 true,但 F 是 false。你的方法将返回 false,这应该是 true。情况可能是这样。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文