Future reference:

    def get_parent_resource(target_klass, path)
      # Convert the requested path into hash form
      hash = ActionController::Routing::Routes.recognize_path
(path, :method => :get)

      # Loop through path keys and see if any end in '_id' and our kid
class belongs_to the associated AR Class
      pair = hash.detect{|k, v| k.to_s.ends_with?("_id") &&
target_klass.columns_hash.has_key?(k.to_s)}

      # Load up the AR class based on the matching path pair
      klass = pair[0].to_s[0...-3].classify.constantize

      # Find and return the target parent object
      klass.find(pair[1])
    end


I'm sure it doesn't work in all cases, but I think it gets pretty
close.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to