如何通過範圍做複選框搜索紅寶石如何使用範圍
我有形式這樣
<% VenueCategory.all.each do |c| %>
<%= check_box_tag("venue_categories[]", c.id)%>
<%= c.name%>
<% end %>`
我要搜索的場地類別,如果多一種選擇是用寫複選框活動記錄搜索選擇。如何使用範圍做
我想這樣 在我property.rb
模型
scope :venue_category, -> (venue_categories_id) { where venue_category_ids: venue_categories }
控制器:
@properties = Property.where(:status=>'1') @properties = @properties.venue_categories(params[:venue_categories]) if params[:venue_categories].present?
模型venuecategory.rb
class VenueCategory < ActiveRecord::Base belongs_to :property end
property.rb
class Property < ActiveRecord::Base has_and_belongs_to_many :venue_categories end
我得到錯誤,當我嘗試這樣做。
我不知道如何使用範圍進行多個複選框選項搜索。如果有人知道,請幫助我。
任何幫助是可觀的。
你有什麼錯誤? –
@Anthony E未定義的方法'venue_categories'的# –
SreRoR
現在我改變了控制器像這樣@properties = @ properties.venue_category if params [:venue_categories] .present?'那麼我得到這個錯誤在我的屬性模型'參數錯誤(0爲1)' – SreRoR