Created
October 31, 2010 21:55
-
-
Save tcocca/657214 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#file: app/themes/blue/mixins/blue_users_controller_mixin.rb | |
module BlueUsersControllerMixin | |
def blue_show | |
#themed_show method here | |
end | |
end | |
# app/controllers/users_controller.rb | |
class UsersController < ApplicationController | |
before_filter :set_current_theme_mixin | |
def base_show | |
#original (default) show method | |
end | |
def method_missing(method_name, *args, &block) | |
name = method_name.to_s | |
if self.respond_to?("#{current_company.theme}_#{name}") | |
self.send("#{current_company.theme}_#{name}") | |
elsif self.respond_to?("base_#{name}") | |
self.send("base_#{name}") | |
else | |
super | |
end | |
end | |
private | |
def set_current_theme_mixin | |
if File.exists?(RAILS_ROOT, 'app', 'themes', current_company.theme, 'mixins', "#{current_company.theme}_#{params[:controller]}_controller_mixin.rb") | |
@controller.extend("#{current_company.theme}_#{params[:controller]}_controller_mixin".constantize) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment