views:

72

answers:

1

I have a view with the flexigrid component on it. When the view calls the mickey_mouses_controller#new action, the flexigrid component calls mickey_mouses_controller#grid_data action (via localhost:3000/mickey_mouse/grid_data) and returns the relevant json objects correctly.

However, when I submit my view so the ActiveRecord validations fail and renders the view again (mickey_mouses_controller#create action), the flexigrid component is attempting to call the mickey_mouses_controller#grid_data action through localhost:3000/grid_data (instead of localhost:3000/mickey_mouses/grid_data) which is causing the following error.

No route matches "/grid_data" with {:method=>:post}

This is what I have in my routes.rb:

map.resources :mickey_mouse, :collection => {:grid_data => [:get, :post]}

Why is this happening and how can I fix it?

Appreciate any ideas to troubleshoot this and thanks in advance :)

A: 

How have you configured the flexgrid javascript? For your routes it should look like this:

$("#flex1").flexigrid({
    url: 'http://localhost:3000/mickey_mouses/grid_data',
    // other options ...
});

The other to get round it would be to add an extra route:

map.connect '/grid_data', :controller => 'mickey_mouses', :action => 'grid_data'

Although this will may not be ideal if you want multiple flexigrids in your application.

Andrew Nesbitt
Thanks! I changed flexigrid's url attribute from>>url: 'grid_data'to be>>url: '/mickey_mouses/grid_data'and this seemed to do it.
obiwanchinobi