获取完整的 rails 控制器名称,包括命名空间 [英] Get full rails controller name, including the namespace
问题描述
我在不同的命名空间中有很多控制器.controller_name 方法只返回控制器的名称,例如文章".有没有机会获得像service/articles"这样的全名(文章控制器在服务命名空间中)?
I've many controllers in different namespaces. The controller_name method only returns the name of the controller, e.g. 'articles'. Is there any chance to get the full name like 'service/articles' (the articles controller is in the service namespace)?
我想通过全局使用的部分创建指向每个控制器的索引操作的链接:
I want do create a link to the index action of each controller via a globally used partial:
<%= link_to controller.display_name, { :controller => controller.controller_name, :action => "index"} %>
如果在users"命名空间的视图中呈现此部分,我会收到错误消息:users/articles 没有路由(它应该是 service/articles).
If this partial is rendered in a view in the 'users' namespace, I get an error: users/articles has no route (it should be service/articles).
推荐答案
您是否尝试过:
controller_path
http://api.rubyonrails.org/classes/AbstractController/Base.html#method-i-controller_path
这篇关于获取完整的 rails 控制器名称,包括命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!