19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'app/models/concerns/rooftop/rails/nested_model.rb', line 19
def find_by_nested_path(path, opts = {})
options = {delimiter: '/', unescape: false}
options.merge!(opts)
path = CGI::unescape(path) if options[:unescape]
delimiter = options[:delimiter]
slug = "#{options[:prefix]}#{path}".gsub(/^\//, '').split(delimiter).last
entities = where(slug: slug)
entity = entities.to_a.find {|e| e.nested_path == path}
if entity.nil?
raise Rooftop::RecordNotFoundError, "Couldn't find #{self} with slug #{slug}"
else
return entity
end
end
|