문제

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?

도움이 되었습니까?

해결책

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?
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top