Permalink
Browse files

dynamically add controller and helper methods for identifying request…

… type
  • Loading branch information...
matthewrobertson committed Jan 29, 2013
1 parent b21951e commit 64ea3574d5b8aa6ef1da673c791e7ced0b3df124
Showing with 11 additions and 0 deletions.
  1. +11 −0 lib/ress/category_collection.rb
@@ -15,9 +15,20 @@ def set_canonical(options = {})
def add_alternate(options)
version = AlternateVersion.new(options.delete(:name), options.delete(:media), options)
+ define_helper_method(version) if defined? ActionController::Base
alternate_versions << version
end
+ private
+
+ def define_helper_method(version)
+ method_name = "#{version.name}_request?".to_sym
+ ActionController::Base.send(:define_method, method_name) do
+ version.matches?(request.subdomain)
+ end
+ ActionController::Base.helper_method(method_name)
+ end
+
end
end

0 comments on commit 64ea357

Please sign in to comment.