Skip to content

Instantly share code, notes, and snippets.

@tcocca
Created October 31, 2010 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tcocca/657214 to your computer and use it in GitHub Desktop.
Save tcocca/657214 to your computer and use it in GitHub Desktop.
#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