Rails 验证页面导致路由错误
我有一个带有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你是如何配置 flexgrid javascript 的?对于您的路线,它应该如下所示:
另一种解决办法是添加一条额外的路线:
尽管如果您希望在应用程序中使用多个灵活网格,这可能并不理想。
How have you configured the flexgrid javascript? For your routes it should look like this:
The other to get round it would be to add an extra route:
Although this will may not be ideal if you want multiple flexigrids in your application.