Rails 当前页面,除非替代

Rails Current Pages unless alternative

为了寻找更好的方法和更简洁的代码,

我正在寻找 Rails 在 application.html.erb 上渲染页面,因为我知道 'render unless' 是如何工作的 喜欢

     <%= render 'shared/jumbotron' unless  
                        current_page?(page2_path) ||
                        current_page?(page3_path) ||
                        current_page?(page4_path) ||
                        current_page?(page5_path) || 
                        current_page?(page6_path) || 
                        current_page?(page7_path) || 
                        current_page?(page8_path) || 
                        current_page?(page9_path)%>

因为我不喜欢这段代码,因为我觉得它有点受阻或混乱,因为我认为一页可以,但不要超过 10 页,因为

我想要这个页面列表来替换 page1_path 它只会显示 page1_path 而不是像下面这样的其余所有路径

 <%= render 'shared/jumbotron' "something like that Show only" 
                            current_page?(page1_path)%>

因此,如果我在 application.html.erb 中创建新路径,则不必每次都添加。

您可以在语句后使用 ifunless。因此,如果您只想在单个页面上呈现 jumbotron,您可以这样做:

 <%= render 'shared/jumbotron' if current_page?(page1_path)%>