Reputation: 3196
Normally rails would automatically render the file corresponding to the controller and action. For example an action index
in TestController
could render the file app/views/test/index.html.erb
. Is there a dynamic way where I can get the path of the corresponding action view file? For example, if I have test#something
I want to get app/views/test/something.html.erb
.
Upvotes: 6
Views: 3223
Reputation: 52377
It is possible. Check out LookupContext and view_renderer
.
Within controller's action:
lookup_context.find_template("#{controller_path}/#{action_name}").identifier
Within view:
@view_renderer.lookup_context.find_template(@virtual_path).identifier
Upvotes: 8