Rails 验证页面导致路由错误

发布于 2024-08-16 05:41:36 字数 690 浏览 3 评论 0原文

我有一个带有 Flexigrid 组件的视图。当视图调用 mickey_mouses_controller#new 操作时,flexigrid 组件调用 mickey_mouses_controller#grid_data 操作(通过 localhost:3000/mickey_mouse/grid_data)并正确返回相关的 json 对象。

但是,当我提交视图时,ActiveRecord 验证失败并再次呈现视图(mickey_mouses_controller#create 操作),flexigrid 组件尝试通过 localhost:3000/grid_data (而不是 localhost:3000/mickey_mouses)调用 mickey_mouses_controller#grid_data 操作/grid_data) 导致以下错误。

<块引用>

没有路线与“/grid_data”与 {:method=>:post} 匹配

这是我在routes.rb中的内容:

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

为什么会发生这种情况以及如何修复它?

感谢任何解决此问题的想法,并提前致谢:)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

朕就是辣么酷 2024-08-23 05:41:36

你是如何配置 flexgrid javascript 的?对于您的路线,它应该如下所示:

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

另一种解决办法是添加一条额外的路线:

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

尽管如果您希望在应用程序中使用多个灵活网格,这可能并不理想。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文