我的表单没有将必要的参数 params[:tag_ids] 发送到控制器。我无法弄清楚我做错了什么?
路由.rb
put 'posts_filter', to: 'articles#index', as: :posts_filter
查看/文章/index.html.haml
%ul{style: "list-style-type: none; margin: 0px; padding: 0px;"}
= form_tag posts_filter_path, remote: true, method: :put do
- @tags.each do |tag|
- if tag.count_of_articles != 0
%li.content
= check_box_tag "tag_ids[]", tag.id, @selected_tag_ids.first.blank? ? true : @selected_tag_ids.include?(tag.id.to_s) ? true : false
= "#{tag.name} (#{tag.count_of_articles})"
= submit_tag "Filter", class: "btn"
控制器/articles_controller
def index
@tags = Tag.asc
logger.info params.inspect
if params[:tag_ids].present?
logger.info params[:tag_ids].inspect
@articles = Article.where(id: Tagging.pluck_taggable_ids(params[:tag_ids])).desc.page(params[:page]).per(24)
@selected_tag_ids = params[:tag_ids]
else
logger.info "nononoononononononono"
@articles = Article.pub.desc.page(params[:page]).per(24)
@selected_tag_ids = []
end
respond_to do |format|
format.html
format.js
end
结尾