开发者

Rails validation page causes a routing error

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 :)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜