我有一个javascript触发ajax请求,其结果被加载到弹出对话框中。
在所有情况下都是相同的javascript,但在一种情况下,路由失败。
来自new_army_list页面:
Started POST "/army_lists/preview" for 127.0.0.1 at 2010-10-13 21:42:15 -0400
Processing by ArmyListsController#preview as */*
来自edit_army_list页面:
Started POST "/army_lists/preview" for 127.0.0.1 at 2010-10-13 21:40:35 -0400
ActionController::RoutingError (No route matches "/army_lists/preview"):
Rendered /home/bluepojo/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.3ms)
有问题的javascript:
function preview() {
$.facebox(function() {
var post_data = $('form').serialize();
$.post('/army_lists/preview', post_data, function(data) {
$.facebox(data);
});
});
}
知道发生了什么事吗?我无法弄清楚从哪里开始调试它。
更新:路线:
preview_army_list POST /army_lists/preview(.:format) {:controller=>"army_lists", :action=>"preview"}
UPDATE2:观看次数
!!! XML
!!!
%head
%title
Skirmisher
= stylesheet_link_tag 'screen'
= stylesheet_link_tag 'facebox/facebox'
= yield :stylesheets
= javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js'
= javascript_include_tag 'facebox/facebox'
= yield :javascripts
= csrf_meta_tag
%body
#wrapper
#wrapper-top
= yield
= render :partial => 'shared/get_satisfaction_tab'
= render :partial => 'form'
= render :partial => 'form'
- content_for :javascripts do
= javascript_include_tag 'new_list'
= form_for @army_list do |f|
-if @army_list.errors.any?
#errorExplanation
%h2= "Fix #{pluralize(@army_list.errors.count, "error")} to save your list:"
%ul
- @army_list.errors.full_messages.each do |msg|
%li= msg
.paper-super-wrapper
.paper-wrapper
= render :layout => 'shared/sidebar' do
%li
= f.submit 'Save', :id => 'save'
%li.last
%a{:href => '#', :title => 'Preview', :id => 'preview'}
Preview
= render :partial => 'floating_label', :locals => {:label => 'Title'}
.paper-wrapper
= render :layout => 'shared/paper' do
= f.text_field :title, :class => 'list-input'
.paper-wrapper
= render :layout => 'floating_label', :locals => {:label => 'Army List'} do
%li.first-common.last
#new-section-button.button-div
+ Section
#new-unit-button.button-div
+ Unit
= render :layout => 'shared/paper' do
= f.text_area :list, :class => 'list-input', :id => 'the-list'
= render :partial => 'floating_label', :locals => {:label => 'Tags'}
.paper-wrapper
= render :layout => 'shared/paper' do
= f.text_field :tag_list, :class => 'list-input'
答案 0 :(得分:1)
事实证明我正在捕捉_method: put
参数而没有意识到,因为我正在序列化表单。
通过单独拉出值来解决问题。