我创建了一组路线 &具有 admin 命名空间的控制器,我在使用具有这些新路由的链接助手时遇到了一些问题.
I've created a set of routes & controllers with the admin namespace, and I was having some issues using the link helpers with these new routes.
我看到有一些新的路径帮助器,例如 admin_projects_path,它指向/admin/projects.但是,我无法链接到命名空间内这些对象的显示、编辑、销毁等路径.我该怎么做?
I see that there are some new path helpers, such as admin_projects_path which leads to the /admin/projects. however, i'm having trouble linking to the show, edit, destroy, etc. paths for these objects within the namespace. how do I do that?
推荐答案您应该会看到 rake routes 中列出的所有路由,并且可以通过名称使用这些路由来获得正确的命名空间.在您手动传入 :controller 和 :action 的地方使用自动检测不会像您发现的那样工作.
You should see all of your routes listed in rake routes and you can use those by name to get the proper namespacing. Using the automatic detection where you pass in :controller and :action manually won't work as you've discovered.
如果它在路由中被列为 new_thing,则该方法是带有适当参数的 new_thing_path.例如:
If it's listed as new_thing in the routes, then the method is new_thing_path with the appropriate parameters. For instance:
link_to('New Project', new_admin_project_path) link_to('Projects', admin_projects_path) link_to(@project.name, admin_project_path(@project)) link_to(@project.name, edit_admin_project_path(@project)) link_to(@project.name, admin_project_path(@project), :method => :delete)更多推荐
rails 使用 link
发布评论