Ruby on rails 3 Rails Ajax表单:无法理解我做错了什么
我的表单没有向控制器发送必要的参数params[:tag_id]。我不知道我做错了什么 Routes.rbRuby on rails 3 Rails Ajax表单:无法理解我做错了什么,ruby-on-rails-3,jquery,Ruby On Rails 3,Jquery,我的表单没有向控制器发送必要的参数params[:tag_id]。我不知道我做错了什么 Routes.rb put 'posts_filter', to: 'articles#index', as: :posts_filter Views/articles/index.html.haml %ul{style: "list-style-type: none; margin: 0px; padding: 0px;"} = form_tag posts_filter_path, remote:
put 'posts_filter', to: 'articles#index', as: :posts_filter
Views/articles/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"
控制器/物品控制器
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
结束将您的选项卡设置为升华编辑器选项卡: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请求…您能否在firebug或chrome developer工具中检查表单并放置表单数据。请