On Dec 11, 2007, at 1:41 PM, Justin Wienckowski wrote:
> I''ve run into the need to test for the existence of template files
in
> several Rails apps I''ve worked on. Particularly in circumstances
> where I''m rendering a partial, and use a different partial
template
> for different sub-classes of a model object. When doing so, I often
> test to make sure the template file exists first, and simply skip
> that item if no template exists.
>
> So right now I rely on a cludgy and annoying:
>
> File.exist?( File.join( ActionController::Base.template_root,
> "layouts", "some_subdir", "_%s.rhtml" %
method_param ))
>
>
> Anyone have a better, more elegant (and less hackish) method of doing
> this?
I discuss some techniques for this in
http://www.railsdev.ws/blog/3/modular-page-assembly-in-rails/
You might consider using request.controller and request.action, and/
or creating a hash of path names so you can centralize @path_names
[''x''] vs hard coding those directories.
--
def gw
acts_as_n00b
writes_at(www.railsdev.ws)
end
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---