Nick
2010-Feb-26 03:25 UTC
Get the path within a template (as in Rails template, not view template)
Hi guys. In one of my Rails templates (the type of template that you pass to "rails -m template.rb"), I''m trying to determine the path of the template. I''ve checked for instance variables from within the template, but only @root and @logger exist. Is there a way for the template to determine its path, or at least which directory it''s located in? Thanks! Nick -- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Steve Rowley
2010-Feb-26 04:35 UTC
Re: Get the path within a template (as in Rails template, not view template)
> Is there a way for the template to determine its path, or at least > which directory it''s located in?Can you use __FILE__? Or File.dirname(__FILE__) if you just want the directory? Best, Steve -- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Nick
2010-Feb-26 05:04 UTC
Re: Get the path within a template (as in Rails template, not view template)
On Feb 25, 11:35 pm, Steve Rowley <srow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Is there a way for the template to determine its path, or at least > > which directory it''s located in? > > Can you use __FILE__? Or File.dirname(__FILE__) if you just want the > directory?Unfortunately not. It seems the template is pushed through #eval. This: puts "file = [#{__FILE__.inspect}]" outputs this: file = ["(eval)"] -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.