1st Wed
build_named_route_callに関するメモ
polymorphic_urlの中身で使われている build_named_route_callのソースを貼付けておきます。
ruby>>
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
string << "#{RecordIdentifier.send("plural_class_name", parent
)}".singularize
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
<<--
posted by
genki on Wed 1 Apr 2009 at 13:13 with 0 comments