Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get path of corresponding controller action view file

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.

like image 936
harinsa Avatar asked Dec 07 '15 04:12

harinsa


1 Answers

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
like image 110
Andrey Deineko Avatar answered Oct 30 '22 04:10

Andrey Deineko