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 given 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With