Hi, I would like to have the ability for my application''s .rhtml files to be customized after I give my app to a client. However I don''t want them to mess with the existing templates. Basically I would like to look in a directory lets say "customize" which would be off the RAILS_ROOT directory. If a .rhtml is in the "customize" there use that one, if not use the one in the standard location under app/views. Is this possible? So my directory strucure would look like: RAILS_ROOT app controller views public customize Thanks, scott. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Scott F. Walterscottwalter.com --explorer what''s new
You need to extend some ActionView stuff in Rails. Basically you need to intercept ActionView when it tried to determine the path to load a view, and check to see if you have a view of the same name in your custom location. My team and I have written the code to do with, we''re currently looking at how we can open-source it without our employers freaking out. Essentially, you''ll need to have the following code loaded from somewhere (I suppose at a pinch even putting this into environment.rb might work) module ActionView class Base private def full_template_path(template_path, extension) # return the file in the regular RAILS_ROOT/app/views if it exists default_template = "#{@base_path}/#{template_path}.#{extension}" return default_template if File.exist?(default_template) # If it didn''t, return the custom patch based on your location site_specific_path = File.join(DirectoryToYourCustomViews, template_path.to_s + ''.'' + extension.to_s) return site_specific_path if File.exist?(site_specific_path) # If we couldn''t find either, lets assume that it''s a user coding error and return # what would be the original path. return default_template end end end (note, this is for Rails 0.13.1, I don''t know if anything has changed in 0.14.1 that might break this) This is a fragment of a larger scale plugins-style system that we''ve developed which is capable of loading views/controllers/models/helpers from multiple locations, and lets you override parts as you require. We''re hoping that trunk Rails will be able to absorb much of this functionality into its own plugins system as soon as we are allowed to share it. I need to chat a bit more to Jamis before this becomes a reality though. Stay tuned... - James On 10/24/05, Scott Walter <tx_scottwalter-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> > Hi, > > I would like to have the ability for my application''s > .rhtml files to be customized after I give my app to a > client. However I don''t want them to mess with the > existing templates. Basically I would like to look in > a directory lets say "customize" which would be off > the RAILS_ROOT directory. If a .rhtml is in the > "customize" there use that one, if not use the one in > the standard location under app/views. Is this > possible? > > So my directory strucure would look like: > > RAILS_ROOT > app > controller > views > public > customize > > Thanks, scott. > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Scott F. Walterscottwalter.com<http://Walterscottwalter.com>--explorer what''s new > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hello Scott, 2005/10/24, Scott Walter <tx_scottwalter@yahoo.com>:> I would like to have the ability for my application's > .rhtml files to be customized after I give my app to a > client. However I don't want them to mess with the > existing templates. Basically I would like to look in > a directory lets say "customize" which would be off > the RAILS_ROOT directory. If a .rhtml is in the > "customize" there use that one, if not use the one in > the standard location under app/views. Is this > possible?Take a look at the Rails Product Generator[1]. It does exactly what you want. Bye ! François [1] http://wiki.rubyonrails.com/rails/pages/RailsProductGenerator _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
As a footnote on why we haven''t used ''Productization'' and developed our own method... Productization requires you to have a single Rails project which has all of the common code within it. While this is great for many applications, it also means that any bugs will be common across all of your sites, and all of your sites must use the same ''version'' of the core code. By adopting more of a plugin approach, you can isolate components and use them only when needed. You can also manage different versions of the common functionality across your differrent sites. It really depends on how you work and the requirements of the sites you''re developing. Our approach is better for developing applications running on seperate servers which require subsets of our team''s total developed functionality. Different team members can develop each component in isolation and applications can require tagged versions of these components while trunk development continues apace. Productisation is much more like virtual serving as you might find in Apache - the single same core application running on one server (I''m resisting the word ''monolithic here ;-)), with smaller tweaks (e.g. layouts, stylsheets) depending on the hostname that server is accessed with. It''s horses for courses.... On 10/24/05, Francois Beausoleil <francois.beausoleil-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hello Scott, > > 2005/10/24, Scott Walter <tx_scottwalter-/E1597aS9LQAvxtiuMwx3w@public.gmane.org>: > > I would like to have the ability for my application''s > > .rhtml files to be customized after I give my app to a > > client. However I don''t want them to mess with the > > existing templates. Basically I would like to look in > > a directory lets say "customize" which would be off > > the RAILS_ROOT directory. If a .rhtml is in the > > "customize" there use that one, if not use the one in > > the standard location under app/views. Is this > > possible? > > Take a look at the Rails Product Generator[1]. It does exactly what you > want. > > Bye ! > François > > [1] http://wiki.rubyonrails.com/rails/pages/RailsProductGenerator > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails