【发布时间】:2016-01-17 23:37:30
【问题描述】:
我已经使用filterrific gem 来过滤 rails 中的模型。
目前,我有三个模型,Video、Tagging、Tag
Video.rb
has_one :tagging
has_one :tag, through: :tagging
scope :by_tag, -> (tag_id) {joins(:tagging).where(taggings: {tag_id: tag_id})}
因为tag.name很难做过滤(见StackOverflow),所以我在join table tagging中使用tag_id做过滤。
标记.rb
belongs_to :video
belongs_to :tag
标签.rb
has_many :taggings
has_many :videos, through: :taggings
目前scope正在工作,但我不知道如何编写controller和view
在控制器中:如何编写select_options 方法?
观点:select方法怎么写?目前,我这样写,但不工作:
f.select(:by_tag, Tag.all, { include_blank: '- Any -' }, :class=>'form-control')
【问题讨论】: