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.
精彩评论