From 69283303f3efe4e3c1f58afa8044f9572ee71f16 Mon Sep 17 00:00:00 2001 From: Nishant Modak Date: Tue, 7 Apr 2015 02:43:49 +0530 Subject: [PATCH 1/2] view paths docs [ci skip] --- guides/source/action_view_overview.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/guides/source/action_view_overview.md b/guides/source/action_view_overview.md index 02ef32d66e5..b31be6577b8 100644 --- a/guides/source/action_view_overview.md +++ b/guides/source/action_view_overview.md @@ -356,7 +356,23 @@ Supposing we use the same `_box` partial from above, this would produce the same View Paths ---------- -TODO... +In case, you want to modify the default view path of a controller, you could either prepend or append to the view path, based on the need of looking it up before or after. + +### Prepend view path + +Example: Change view paths for different sub-domains. Prepend to the view path by doing + +```prepend_view_path "app/views/#{request.subdomain}"``` + +After this, views will be looked up in this order ```[~/rails_app/app/views/, ~/rails_app/app/views]``` + +### Append view path + +Similarly, to append to the view paths you would do it with + +```append_view_path "app/views/direct"```. + +This would add ```app/views/direct``` and the end of lookup paths for views. Overview of helpers provided by Action View ------------------------------------------- From 8b0aa0c1b1d695a3105dc3236cc2fbda80d5b536 Mon Sep 17 00:00:00 2001 From: Zachary Scott Date: Sun, 12 Apr 2015 14:43:25 -0700 Subject: [PATCH 2/2] Some copy edits for modifying View Paths [ci skip] --- guides/source/action_view_overview.md | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/guides/source/action_view_overview.md b/guides/source/action_view_overview.md index 6021387bdbb..44c02165db8 100644 --- a/guides/source/action_view_overview.md +++ b/guides/source/action_view_overview.md @@ -356,23 +356,39 @@ Supposing we use the same `_box` partial from above, this would produce the same View Paths ---------- -In case, you want to modify the default view path of a controller, you could either prepend or append to the view path, based on the need of looking it up before or after. +When rendering the view for a request, the controller needs to resolve where to find each of the directories are located. + +We are able to modify the order these locations are resolved by using `prepend_view_path` and `append_view_path`. + +This allows us to add new paths to the beginning or end of the list used to resolve these paths. ### Prepend view path -Example: Change view paths for different sub-domains. Prepend to the view path by doing +This can be helpful for example, when we want to prepend a different directory for subdomains. + +We can do this by using: ```prepend_view_path "app/views/#{request.subdomain}"``` -After this, views will be looked up in this order ```[~/rails_app/app/views/, ~/rails_app/app/views]``` +Then our list becomes something like: + +``` +[ + ~/rails_app/app/views/, + ~/rails_app/app/views, + # ... +] +``` + +This will put the subdomain path at the beginning of the list. ### Append view path -Similarly, to append to the view paths you would do it with +Similarly, we can append paths: ```append_view_path "app/views/direct"```. -This would add ```app/views/direct``` and the end of lookup paths for views. +This will add ```app/views/direct``` and the end of lookup paths for views. Overview of helpers provided by Action View -------------------------------------------