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

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

On Feb 25, 11:35 pm, Steve R. [email protected] 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)"]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs