有軌道上的任何插件,做相同的頁面railCast。像過濾器一樣使用標籤。使用麪包屑就像一個過濾器
例如,在類型免費劇集點擊(右),在頁面的頂部顯示
應用過濾器:免費劇集
,並與其他類別和類型相同,我點擊「x」刪除這個過濾器...
任何想法!!!!
有軌道上的任何插件,做相同的頁面railCast。像過濾器一樣使用標籤。使用麪包屑就像一個過濾器
例如,在類型免費劇集點擊(右),在頁面的頂部顯示
應用過濾器:免費劇集
,並與其他類別和類型相同,我點擊「x」刪除這個過濾器...
任何想法!!!!
這些被認爲是tags
使用寶石acts-as-taggable-on
(http://railscasts.com/episodes/382-tagging)。
如果您只是基於標籤進行搜索,您可以使用搜索寶石,如solr
或ransack
(http://railscasts.com/episodes/370-ransack)搜索這些搜索或創建自己的搜索操作。
在railscasts網站上有一個類型參數集,如果您點擊其中一個情節類型。必須有一個處理類型參數的索引操作 - 如果設置,只查詢特定類型的參數,如果不是,則查詢所有劇集。這很容易。它可能看起來像下面的例子:
class EpisodesController < ApplicationController
def index
if params[:type]
@episodes = Episode.where(:specifc_type => params[:type])
# or
@episodes = Episode.to_klass(params[:type]).all # if you are using STI and have a to_klass method in your model, which generates the class constant out of the params, e.g => params[:type] => "pro", Episode.to_klass("pro") => ProEpisode, or something similar
else
@episodes = Episode.all
end
end
end
而且在你看來簡單的渲染過濾
應用程序/視圖/次/ index.html.erb
<% if params[:type] %>
<div class="filters">
<strong>Applied Filters:</strong>
<span class="filter">
<%= your_helper_display_name(params[:type]) %>
<%= link_to "x", root_path %> # removes the type params => the else case in your index action will be called.
</span>
</div>
<% end %>