Question

For example,

@foo = Foo.new
@foo.to_partial_path #=> '/foos/foo'

Is there some method I can use to find the full path of the file?

@foo = Foo.new
@foo.something #=> 'app/views/foos/_foo.html.erb'

I could infer it from the partial path, but the problem is that not all of my models are in my main Rails app. Some are within Rails engines, so their view path would be like 'engines/myengine/app/views/...' instead. to_partial_path does not reflect that.

Rails has no trouble rendering the view when I am rendering from the controller. How do I find out what it is using to determine the path?

Was it helpful?

Solution

In model:

def self.Ping
  puts "#{__FILE__}"
end

UP1: Where Rails resolve pathes:

https://github.com/rails/rails/blob/c19958015fac7b50f8dedbdf17991c00d6b8bbd4/actionview/lib/action_view/view_paths.rb


UP2: Rails has no trouble rendering the view when I am rendering from the controller. How do I find out what it is using to determine the path?

Why need you doing that?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top