I had a problem with the comments controller crasher when trying to
figure out the routes for STI classes derived from User (Vendor and
Client in my case).

I ended up hacking it this way (but was wondering if anyone has a
better solution):

module ActionController
  module PolymorphicRoutes
    def build_named_route_call(records, namespace, inflection, options
= {})
      unless records.is_a?(Array)
        record = extract_record(records)
        route  = ''
      else
        record = records.pop

        route = records.inject("") do |string, parent|
          if parent.is_a?(Symbol) || parent.is_a?(String)
            string << "#{parent}_"
          else
            ## HACK TO NOT CRASH ON POLYMORPHIC ROUTES FOR VENDOR/
CLIENT
            if (parent.class.superclass == User)
              string << "#{RecordIdentifier.__send__
("plural_class_name", parent.class.superclass)}".singularize
            else
              string << "#{RecordIdentifier.__send__
("plural_class_name", parent)}".singularize
            end
            # string << "#{RecordIdentifier.__send__
("plural_class_name", parent)}".singularize
            ## END HACK
            string << "_"
          end
        end
      end

      if record.is_a?(Symbol) || record.is_a?(String)
        route << "#{record}_"
      else
        route << "#{RecordIdentifier.__send__("plural_class_name",
record)}"
        route = route.singularize if inflection == :singular
        route << "_"
      end

      action_prefix(options) + namespace + route + routing_type
(options).to_s
    end
  end
end

--

You received this message because you are subscribed to the Google Groups 
"CommunityEngine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/communityengine?hl=en.


Reply via email to