3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/gretel/model_extractor.rb', line 3
def self.(path)
return nil unless path.split('?')[0].match(/\/\d+$/) return nil unless options = ActionController::Routing::Routes.recognize_path(path, :method => :get)
model_name = begin
options[:controller].split('/').last.singularize.camelize.constantize
rescue
return nil unless controller = (options)
return nil unless controller.respond_to?(:model_name)
controller.model_name
end
model_name.find_by_id(options[:id])
rescue ActionController::RoutingError, ActiveRecord::RecordNotFound => e
return nil
end
|