对表演和铁路路线没有回应
我已经正确设置了文件结构(我认为!),并且声称没有任何响应显示。
我的文件结构:
views/admin/admin_wysi/index.html.haml
我的控制器(controllers/admin/admin_wysis_controller.rb)
class Admin::AdminWysisController < Admin::ApplicationController
def index
end
end
我的routes.rb
map.namespace :admin do |admin|
admin.resource :admin_wysi
end
当我尝试访问www.website.com/admin/admin_wysi/时我的错误:
Unknown action
No action responded to show. Actions: index
我在这里做错了什么?
I have my file structure set up appropriately ( I think ! ) , and claims nothing responds to show.
My file structure :
views/admin/admin_wysi/index.html.haml
My controller ( controllers/admin/admin_wysis_controller.rb )
class Admin::AdminWysisController < Admin::ApplicationController
def index
end
end
My routes.rb
map.namespace :admin do |admin|
admin.resource :admin_wysi
end
And my error when I try to access www.website.com/admin/admin_wysi/ :
Unknown action
No action responded to show. Actions: index
What am I doing wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的路线很独特。但你可能想要复数。
将您的路线定义更改为:
或者,如果您确实想要一条单一路线,请将您的控制器更改为:
除此之外,我建议您阅读 Rails Guides 关于路由,它应该提供更多详细信息,说明如何以及实际发生了什么:)
Your routes are singular. But you probably want plural.
Change your route definition to this:
Or if you really want a singular route, change your controller to this:
I addition to all this i suggest you read Rails Guides about routing, it should give some more details how and what is actually going on :)
错误消息表明它正在寻找“显示”操作而不是“索引”操作。可以尝试的一个命令是“rake paths”(从您的终端)。这将打印您的应用程序支持的路径列表以及它们映射到的控制器/操作。在这种情况下,您的问题通过以下方式解决:
执行“map.resource”仅路由 7 个静态路由中的 6 个(不是索引),因此您必须使用“map.resources”(前提是您拥有多个资源而不是单个资源) )。
The error message is stating that it is looking for a 'show' action instead of a 'index' action. One command to try is 'rake routes' (from your terminal). This will print a list of paths supported by your application and which controller / action they map to. In this case, your issue is fixed with:
Performing "map.resource" only routes 6 of the 7 restful routes (not index), so you must use "map.resources" (provided you have multiple resources as opposed to a single resource).