【问题标题】:What's the best way to selectively render rails partials based on the page loading it根据加载它的页面有选择地呈现rails部分的最佳方法是什么
【发布时间】:2011-12-07 14:51:05
【问题描述】:

例如,所有页面都需要我的页脚部分,但主页有几个单词需要不同,页面 Y 也有一个小改动。

【问题讨论】:

    标签: ruby-on-rails partial-views partials


    【解决方案1】:

    您可以检查控制器和操作名称:

    <% if controller.controller_name == 'Projects' && controller.action_name == 'index' %>
    <p>Alternate content</p>
    <% end %>
    

    或者,您可以将不同的局部变量从相关页面传递给部分:

    <%= render 'my_partial', :do_something_wierd => true %>
    

    然后,在“my_partial”中:

    <% if do_something_wierd %>
    <p>Alternate content</p>
    <% end %>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-12
      • 1970-01-01
      • 2012-01-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多