如何通过范围做复选框搜索红宝石如何使用范围
我有形式这样
<% 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