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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On Fri, Dec 14, 2012 at 2:17 AM, Damjan Rems <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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 ```ruby MyController < ApplicationController prepend_view_path "#{Rails.root}/vendor/myapp/views/myctrl" end ``` OR in your configuration you can apply it globally: ```ruby config.paths["app/views"].unshift("#{Rails.root}/vendor/myapp/views/myctrl") ``` -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Jordon Bedwell wrote in post #1089069:> On Fri, Dec 14, 2012 at 2:17 AM, Damjan Rems <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > 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> > ```ruby > MyController < ApplicationController > prepend_view_path "#{Rails.root}/vendor/myapp/views/myctrl" > end > ``` > > OR in your configuration you can apply it globally: > > ```ruby > 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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Jordon Bedwell
2012-Dec-14 09:27 UTC
Re: Re: How to add additional path for views location
On Fri, Dec 14, 2012 at 3:08 AM, Damjan Rems <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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. ```ruby 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: ```ruby 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. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Jordon Bedwell wrote in post #1089073:> ```ruby >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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.