开发者

helper for all views in a namespace

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜