2013-09-22 60 views
0

我的表單沒有向控制器發送必要的params params [:tag_ids]。我無法弄清楚我做錯了什麼?Rails Ajax表單:無法確定我做錯了什麼

的routes.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 

+0

您可以檢查在Firebug或Chrome開發者工具的形式,並把表單數據。請 –

回答

0

讓你的標籤設置崇高的編輯[R標籤: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請求....