Created
November 17, 2016 14:41
-
-
Save ljones140/ad4233b2a8e9e219b15ffb4cd2585866 to your computer and use it in GitHub Desktop.
Rails controller view path and lookup context prefixes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# While having issues with to_partial_path on a view model giving inconsistent results under differing name spaces of controllers | |
# I use the below to see that the look up path and view paths were on an controller and modify. | |
# I've never put the below into production. This is merely something I found while experimenting. | |
# To sort my issue I used the prefixes avaialable and changed name spacing to give correct behaviour | |
class SomeController < ApplicationController | |
# Prepending (or appending) the view path allows you to add the location of view files | |
before_filter :prepend_view_paths | |
def prepend_view_paths | |
prepend_view_path "app/views/backoffice" | |
end | |
# the look up context prefix is used as the prefix for to_partial_path on views. You can add to this with the below. | |
# Be aware it will affect all of your applications lookup_contexts so you need to clear | |
def index | |
lookup_context.prefixes.prepend 'backoffice' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment