Is there a way to create a view helper file that will be available to all views in a namespace? Like application_helper.rb, but only working for a 开发者_如何学Cgiven namespace.
Specifically, I have a namespace called "office". I want to set up a view helper that is accessible to any view within the "office" namespace.
Thanks.
I would suggest that you have a BaseController for that specific namespace. For example,
class Office::BaseController < ApplicationController
  helper :office   
end
And inherit this controller in all the other controllers within that namespace.
class Office::UsersController < Office::BaseController
  def index
      ..
  end
end
Now all the methods within the helper office_helper.rb is present within this namespace.
Also, this is a good practice to separate the concerns / code for the controller namespaces.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论