A resolver that loads files from the filesystem. It allows to set your own resolving pattern. Such pattern can be a glob string supported by some variables.

Examples

Default pattern, loads views the same way as previous versions of rails, eg. when you’re looking for `users/new` it will produce query glob: `users/new{.{en},}{.{html,js},}{.{erb,haml},}`

  FileSystemResolver.new("/path/to/views", ":prefix/:action{.:locale,}{.:formats,}{.:handlers,}")

This one allows you to keep files with different formats in seperated subdirectories, eg. `users/new.html` will be loaded from `users/html/new.erb` or `users/new.html.erb`, `users/new.js` from `users/js/new.erb` or `users/new.js.erb`, etc.

  FileSystemResolver.new("/path/to/views", ":prefix/{:formats/,}:action{.:locale,}{.:formats,}{.:handlers,}")

If you don’t specify pattern then the default will be used.

In order to use any of the customized resolvers above in a Rails application, you just need to configure ActionController::Base.view_paths in an initializer, for example:

  ActionController::Base.view_paths = FileSystemResolver.new(
    Rails.root.join("app/views"),
    ":prefix{/:locale}/:action{.:formats,}{.:handlers,}"
  )

Pattern format and variables

Pattern have to be a valid glob string, and it allows you to use the following variables:

  • :prefix - usualy the controller path
  • :action - name of the action
  • :locale - possible locale versions
  • :formats - possible request formats (for example html, json, xml...)
  • :handlers - possible handlers (for example erb, haml, builder...)
Methods
#
E
N
T
Class Public methods
new(path, pattern=nil)
     # File actionpack/lib/action_view/template/resolver.rb, line 218
218:     def initialize(path, pattern=nil)
219:       raise ArgumentError, "path already is a Resolver class" if path.is_a?(Resolver)
220:       super(pattern)
221:       @path = File.expand_path(path)
222:     end
Instance Public methods
==(resolver)

Alias for eql?

eql?(resolver)
This method is also aliased as ==
     # File actionpack/lib/action_view/template/resolver.rb, line 229
229:     def eql?(resolver)
230:       self.class.equal?(resolver.class) && to_path == resolver.to_path
231:     end
to_path()

Alias for to_s

to_s()
This method is also aliased as to_path
     # File actionpack/lib/action_view/template/resolver.rb, line 224
224:     def to_s
225:       @path.to_s
226:     end