Autoload a view Resolver in rails 4 -
i'm using view resolver override find_templates
method in lib/resolvers/activities_resolver.rb
.
class activitiesresolver < ::actionview::filesystemresolver def initialize super('app/views') end def find_templates(name, prefix, partial, details) super(name, 'activities', partial, details) end end
i'm using in controllerapp/controllers/admin/activities_controller.rb
class admin::activitiescontroller < admin::basecontroller layout 'admin/usability_tests', only: :index append_view_path activitiesresolver.new def index @test = usabilitytest.find(params[:usability_test_id]) @activities = @test.activities end end
in order autoload resolver, added in config/application.rb
:
config.autoload_paths += %w(#{config.root}/lib/resolvers)
this works perfectly, i'd autoload /lib
subdirectories instead of having specify them manually.
i'd write in config/application.rb
:
config.autoload_paths += %w(#{config.root}/lib/**/)
but cannot figure out how make works.
i red had name resolver
class resolvers::activitiesresolver < ::actionview::filesystemresolver
but returns me uninitialized constant
when want initialize in controller.
any ?
thanks in advance !
adding
config.autoload_paths << file.join(config.root, 'lib')
instead of
config.autoload_paths += %w(#{config.root}/lib/**/)
in application.rb
solved problem :)
Comments
Post a Comment