动态改变部分路线

时间:2014-12-11 14:12:26

标签: ruby-on-rails

我的页面上有一个过滤器。

<ul>
    <li>
        <%= link_to "hot", root_path(:filter => ["hot"]) %>
    </li>
    <li>
        <%= link_to "recent", root_path(:filter => ["recent"]) %>
    </li>
    <li>
        <%= link_to "most popular", root_path(:filter => ["popular","day"]) %>
    </li>
    <li>
        <%= link_to "most liked", root_path(:filter => ["liked","day"]) %>
    </li>
</ul>

另一个页面上的几乎完全相同的过滤器(除了路径)(对于后续用户):

<ul>
    <li>
        <%= link_to "hot", followed_index_path(:filter => ["hot"]) %>
    </li>
    <li>
        <%= link_to "recent", followed_index_path(:filter => ["recent"]) %>
    </li>
    <li>
        <%= link_to "most popular", followed_index_path(:filter => ["popular","day"]) %>
    </li>
    <li>
        <%= link_to "most liked", followed_index_path(:filter => ["liked","day"]) %>
    </li>
</ul>

什么是将这些分成一部分的最佳方法?现在我对每个版本都有一个部分,这对我来说似乎很麻烦。

编辑:

我按照以下方式工作:

<ul>
    <li>
        <%= link_to "hot", url_for(:action => "index", :filter => ["hot"]) %>
    </li>
    <li>
        <%= link_to "recent", url_for(:action => "index", :filter => ["recent"]) %>
    </li>
    <li>
        <%= link_to "most popular", url_for(:action => "index", :filter => ["popular","day"]) %>
    </li>
    <li>
        <%= link_to "most liked", url_for(:action => "index", :filter => ["liked","day"]) %>
    </li>
</ul>

1 个答案:

答案 0 :(得分:-1)

您可以尝试实施帮助方法。