0

我的表单没有将必要的参数 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

结尾

4

1 回答 1

0

将您的选项卡设置为 sublime editor tab:2 并粘贴以下代码:

%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"

问题出在ajax请求....

于 2013-09-23T10:16:01.063 回答