How to add additional path for views location

How to add another path where views can be found.

I have an app located in Rails.root/vendor/myapp and have
Rails.root/vendor/myapp/views/myctrl folder for view templates.

It can be done by render :file …, but it is ugly.

How can I add my views path to paths list where it would be
automatically found by Rails controller.

by
TheR

On Fri, Dec 14, 2012 at 2:17 AM, Damjan R. [email protected]
wrote:

How to add another path where views can be found.

See:
http://api.rubyonrails.org/classes/AbstractController/ViewPaths/ClassMethods.html#method-i-prepend_view_path

MyController < ApplicationController
  prepend_view_path "#{Rails.root}/vendor/myapp/views/myctrl"
end

OR in your configuration you can apply it globally:

config.paths["app/views"].unshift("#{Rails.root}/vendor/myapp/views/myctrl")

Jordon B. wrote in post #1089069:

On Fri, Dec 14, 2012 at 2:17 AM, Damjan R. [email protected]
wrote:

How to add another path where views can be found.

See:

http://api.rubyonrails.org/classes/AbstractController/ViewPaths/ClassMethods.html#method-i-prepend_view_path

MyController < ApplicationController
  prepend_view_path "#{Rails.root}/vendor/myapp/views/myctrl"
end

OR in your configuration you can apply it globally:

config.paths["app/views"].unshift("#{Rails.root}/vendor/myapp/views/myctrl")

I forgot to add that I use rails 3.2.9

Second one is not working too.
Missing partial testing/index with {:locale=>[:sl], :formats=>[:html],
:handlers=>[:erb, :builder, :coffee]}. Searched in:

  • “/wwww/rails/testapp/app/views”

“/wwww/rails/testapp/vendor/ruby/1.9.1/gems/kaminari-0.14.1/app/views”

althow debuging shows that path is added to config.paths[“app/views”]
array.

by
TheR

On Fri, Dec 14, 2012 at 3:08 AM, Damjan R. [email protected]
wrote:
Rails version doesn’t matter to me because I only send code for 3.2
but that aside since it’s not working with the first put it into a
before_filter method or you can just provide before_filter with a
proc/block.

MyController < ApplicationController
  before_filter {
    prepend_view_path(Rails.root.join("vendor/myapp/views/myctrl").to_s)
  }
end

Second one is not working too. Missing partial testing/index
SNIP
“/wwww/rails/testapp/vendor/ruby/1.9.1/gems/kaminari-0.14.1/app/views”
althow debuging shows that path is added to config.paths[“app/views”]

Actually, it shows that the path is not being added because I forgot
to join the paths. Added is subjective of course, it’s there it’s
just not there properly which to me it is not there because it’s not
the intended behavior it should be:

config.paths["app/views"].unshift(Rails.root.join("/vendor/myapp/views/myctrl").to_s)

The to_s might not be needed, I don’t quite remember if Rails will
work with Pathname on app/views or if it expects a string, but based
on it’s output I would expect it to always want to work with a string.

Jordon B. wrote in post #1089073:


config.paths[“app/views”].unshift(Rails.root.join("/vendor/myapp/views/myctrl").to_s)


The to_s might not be needed, I don't quite remember if Rails will
work with Pathname on app/views or if it expects a string, but based
on it's output I would expect it to always want to work with a string.

Thanks. It works now.

It looks that path must exist to be included in the searched paths list.

by
TheR