views:

28

answers:

1

I have one bit of javascript that fires off an ajax request, the result of which gets loaded into a popup dialog.

This is the same javascript in all cases, but in one case, the route fails.

From the new_army_list page:

Started POST "/army_lists/preview" for 127.0.0.1 at 2010-10-13 21:42:15 -0400
Processing by ArmyListsController#preview as */*

From the edit_army_list page:

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)

The javascript in question:

function preview() {
  $.facebox(function() {
          var post_data = $('form').serialize();
          $.post('/army_lists/preview', post_data, function(data) {
                   $.facebox(data);
            });
        });
  }

Any idea what's going on? I can't figure out where to begin debugging this.

UPDATE: Route:

preview_army_list POST   /army_lists/preview(.:format) {:controller=>"army_lists", :action=>"preview"}

UPDATE2: Views

application.html.haml

!!! 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'

edit.html.haml

= render :partial => 'form'

new.html.haml

= render :partial => 'form'

_form.html.haml

- 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'
+1  A: 

Turns out I was catching the _method: put parameter without realizing it, as I was serializing the form.

Fixed the issue by pulling the values out individually.

Josiah Kiehl