I have a basic CMS and i’m hugely using cross-controller rendering within it.
class Index < E
map '/'
# some actions
def ad
@steroids = render_p('anabolic-steroids/ads/left-banner')
# some logic
end
end
Steroids class:
class Steroids < E
map 'anabolic-steroids'
# actions
end
View folder:
view/
|
- anabolic-steroids/
|
- ads/
|
- left-banner.erb
# other templates
Everything works well, but now customer wants anabolic-steroids URL
to be renamed into steroids
To make this work i remapped Steroids class:
map :steroids
and renamed view/anabolic-steroids/ folder to view/steroids/.
And Steroids controller works well with new URL.
But now all other controllers that were rendering steroids ad are broken 🙁
And i have to find all places where it is used and rename
render_p('anabolic-steroids/ads/left-banner')
to
render_p('steroids/ads/left-banner')
Odd!
I have also other lot of places where i’m using cross-controller rendering like this.
Any way to avoid useless refactoring
when such innocent renaming requests comes from customers?
Quite long description for a slightly trivial issue 🙂 (joking, sorry, good question though)
The solution is simple, really simple – never use strings where you can use something else…
Seems you missed this on documentation – “To render a template of inner controller, pass controller as first argument and the template as second.”
See official docs here
So to survive any renaming issues use cross-controller rendering like this:
Now you should not worry about “innocent renaming requests” 🙂