提交 6c51cc85 编写于 作者: A Aaron Patterson

extract methods and metaprogram less.

上级 cf38bda8
......@@ -142,22 +142,27 @@ def polymorphic_path(record_or_hash_or_array, options = {})
%w(edit new).each do |action|
module_eval <<-EOT, __FILE__, __LINE__ + 1
def #{action}_polymorphic_url(record_or_hash, options = {}) # def edit_polymorphic_url(record_or_hash, options = {})
polymorphic_url( # polymorphic_url(
record_or_hash, # record_or_hash,
options.merge(:action => "#{action}")) # options.merge(:action => "edit"))
end # end
#
def #{action}_polymorphic_path(record_or_hash, options = {}) # def edit_polymorphic_path(record_or_hash, options = {})
polymorphic_url( # polymorphic_url(
record_or_hash, # record_or_hash,
options.merge(:action => "#{action}", :routing_type => :path)) # options.merge(:action => "edit", :routing_type => :path))
end # end
def #{action}_polymorphic_url(record_or_hash, options = {})
polymorphic_url_for_action("#{action}", record_or_hash, options)
end
def #{action}_polymorphic_path(record_or_hash, options = {})
polymorphic_path_for_action("#{action}", record_or_hash, options)
end
EOT
end
private
def polymorphic_url_for_action(action, record_or_hash, options)
polymorphic_url(record_or_hash, options.merge(:action => action))
end
def polymorphic_path_for_action(action, record_or_hash, options)
options = options.merge(:action => action, :routing_type => :path)
polymorphic_path(record_or_hash, options)
end
class HelperMethodBuilder # :nodoc:
CACHE = { 'path' => {}, 'url' => {} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册