Get full rails controller name, including the namespace

后端 未结 2 733
逝去的感伤
逝去的感伤 2021-02-01 13:21

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 l

相关标签:
2条回答
  • 2021-02-01 14:10

    Have you tried:

    controller_path
    

    http://api.rubyonrails.org/classes/AbstractController/Base.html#method-i-controller_path

    0 讨论(0)
  • 2021-02-01 14:11

    Instead of linking to the :controller, :action syntax, can you use nested resources

    routes.rb

    resources :users do
      resources: articles
    end
    

    in your view

    = link_to 'Articles', user_article_path(current_user)
    

    The user_article will take care of your namespaces for you.

    0 讨论(0)
提交回复
热议问题