標題可能看起來令人困惑,但生病說明我想實現。過濾器列表結果與主過濾器「與多」和次過濾器「只有一個」
我想要什麼:我想conatainer-list
包含在agreement
模式叫writing_type
所有的「類別」,所以每個協議將不得不字符串writing_type。這個container-list
當然會有多個不同的writing_types
。默認情況下會顯示所有的寫入類型。當選擇一個或多個writing_type
的列表將過濾結果到那些writing_type
的。
例如
頁面加載和列表包含所有寫入的類型和降序的所有行。 「選擇的onclick亮點writing_type藍色,可以選擇多,或取消選擇」 具有下列文字類型
容器列表
writing_types:{
college_essay
,college app
,foreign language
}我選擇
college_essay
和foreign language
結果出來只有大學作文和外語
下一個我的交貨期
單擊名爲過濾器的按鈕,結果仍包含
college_essay
和foreign_language
,將由交貨期DESC過濾。會有許多不同的按鈕除了
due_date
像create_at
或price
,但是僅可以在一個時間
- 現在旁邊的下拉是用於次要的按鈕來選擇這些二次濾波器中的一個過濾器
目前這是我現在使用下拉式代碼,但它們都是單獨過濾。我不知道如何先獲取writing_type
,然後點擊其中一個按鈕(如created_at
)進行過濾。
<!-- filters for the categories -->
<div class="row text-center" style="margin:0;padding-bottom:10px;">
<div class="center" style="margin-left:18px;">
<div style="float:left;">
<%= link_to "Title", title_agreements_path, class: "link btn categories-button" %>
</div>
<!-- drop down with the writing types listed -->
<div class="agreements dropdown" style="float:left;margin-top:40px;">
<%= link_to '#', class:'btn categories-button dropdown-toggle', role:'button', style: 'text-decoration:none', 'aria-expanded' =>'false', data:{toggle: 'dropdown'} do %>
Writing Type
<span class="caret"></span>
<% end %>
<ul class="dropdown-menu" style="">
<h>Choose a Writing Type:</h>
<li><%= link_to "College Applications", collegeapplication_agreements_path, class: "link btn categories-button" %></li>
<li><%= link_to "College Essays", collegeessay_agreements_path, class: "link btn categories-button" %></li>
<li><%= link_to "Business Papers", businesspaper_agreements_path, class: "link btn categories-button" %></li>
<li><%= link_to "Resumes", resume_agreements_path, class: "link btn categories-button" %></li>
<li><%= link_to "Scholarship Essays", scholarshipessay_agreements_path, class: "link btn categories-button" %></li>
<li><%= link_to "High-School Essays", highschoolessay_agreements_path, class: "link btn categories-button" %></li>
<li><%= link_to "Language Translation", languagetranslation_agreements_path, class: "link btn categories-button" %></li>
</ul>
</div>
<div style="float:left;">
<%= link_to "Recent", recent_agreements_path, class: "link btn categories-button" %>
</div>
<div style="float:left;margin-top:40px;">
<%= link_to "Oldest", oldest_agreements_path, class: "link btn categories-button" %>
</div>
<div style="float:left;">
<%= link_to "Close Duedate", recentduedate_agreements_path, class: "link btn categories-button" %>
</div>
<div style="float:left;margin-top:40px;">
<%= link_to "Further Duedate", oldestduedate_agreements_path, class: "link btn categories-button" %>
</div>
<div style="float:left;">
<%= link_to "Lowest Price", lowestprice_agreements_path, class: "link btn categories-button" %>
</div>
<div style="float:left;margin-top:40px;">
<%= link_to "Highest Price", highestprice_agreements_path, class: "link btn categories-button" %>
</div>
</div>
</div>
的routes.rb
resources :agreements, path: "agreement" do
collection do
get :recent
get :oldest
get :recentduedate
get :oldestduedate
get :collegeapplication
get :collegeessay
get :businesspaper
get :resume
get :scholarshipessay
get :highschoolessay
get :languagetranslation
get :title
get :lowestprice
get :highestprice
end
end
協議。RB模型
scope :recent, ->{ order("created_at DESC") }
scope :oldest, ->{ order("created_at ASC") }
scope :recentduedate, ->{ order("due_date DESC") }
scope :oldestduedate, ->{ order("due_date ASC") }
scope :lowestprice, ->{ order("current_price ASC") }
scope :highestprice, ->{ order("current_price DESC") }
scope :collegeapplication, ->{ where("writing_type = ?", "College Applications") }
scope :collegeessay, ->{ where("writing_type = ?", "College Essays") }
scope :businesspaper, ->{ where("writing_type = ?", "Business Papers") }
scope :resume, ->{ where("writing_type = ?", "Resumes") }
scope :scholarshipessay, ->{ where("writing_type = ?", "Scholarship Essays") }
scope :highschoolessay, ->{ where("writing_type = ?", "High-School Essays") }
scope :languagetranslation, ->{ where("writing_type = ?", "Language Translation") }
scope :title, ->{ order("title DESC") }
def index
@agreements = Agreement.where("accepted = ?", false).all.paginate(:page => params[:page], :per_page => 20)
end
def recent
@agreements = Agreement.recent.where("accepted = ?", false).all.paginate(:page => params[:page], :per_page => 20)
render action: :index
end
def oldest
@agreements = Agreement.oldest.where("accepted = ?", false).all.paginate(:page => params[:page], :per_page => 20)
render action: :index
end
def recentduedate
@agreements = Agreement.recentduedate.where("accepted = ?", false).all.paginate(:page => params[:page], :per_page => 20)
render action: :index
end
def oldestduedate
@agreements = Agreement.oldestduedate.where("accepted = ?", false).all.paginate(:page => params[:page], :per_page => 20)
render action: :index
end
def collegeessay
@agreements = Agreement.collegeessay.where("accepted = ?", false).all.paginate(:page => params[:page], :per_page => 20)
render action: :index
end
def resume
@agreements = Agreement.resume.where("accepted = ?", false).paginate(:page => params[:page], :per_page => 20)
render action: :index
end
def languagetranslation
@agreements = Agreement.languagetranslation.where("accepted = ?", false).all.paginate(:page => params[:page], :per_page => 20)
render action: :index
end
def collegeapplication
@agreements = Agreement.collegeapplication.where("accepted = ?", false).all.paginate(:page => params[:page], :per_page => 20)
render action: :index
end
def businesspaper
@agreements = Agreement.businesspaper.where("accepted = ?", false).all.paginate(:page => params[:page], :per_page => 20)
render action: :index
end
def scholarshipessay
@agreements = Agreement.scholarshipessay.where("accepted = ?", false).all.paginate(:page => params[:page], :per_page => 20)
render action: :index
end
def highschoolessay
@agreements = Agreement.highschoolessay.where("accepted = ?", false).all.paginate(:page => params[:page], :per_page => 20)
render action: :index
end
def title
@agreements = Agreement.title.where("accepted = ?", false).all.paginate(:page => params[:page], :per_page => 20)
render action: :index
end
def lowestprice
@agreements = Agreement.lowestprice.where("accepted = ?", false).all.paginate(:page => params[:page], :per_page => 20)
render action: :index
end
def highestprice
@agreements = Agreement.highestprice.where("accepted = ?", false).all.paginate(:page => params[:page], :per_page => 20)
render action: :index
end
到目前爲止,我已經做這個和它的作品所有的個體,但我想要的篩選結果是基於什麼writing_type
被選擇作爲主要結果。謝謝!!!
這一切都對我有意義,謝謝你!當我回來確認它的工作時,我會實施! –