Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Removed deprecated parameters_for_method_reference concept (legacy fr…
…om before named routes) [DHH] Added record identification with polymorphic routes for ActionController::Base#url_for and ActionView::Base#url_for [DHH] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6729 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
- Loading branch information
Showing
15 changed files
with
241 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
module ActionController | ||
module PolymorphicRoutes | ||
extend self | ||
|
||
def polymorphic_url(record_or_hash, url_writer, options = {}) | ||
record = extract_record(record_or_hash) | ||
|
||
case | ||
when options[:action] == "new" | ||
url_writer.send(action_prefix(options) + RecordIdentifier.singular_class_name(record) + routing_type(options)) | ||
|
||
when record.respond_to?(:new_record?) && record.new_record? | ||
url_writer.send(RecordIdentifier.plural_class_name(record) + routing_type(options)) | ||
|
||
else | ||
url_writer.send( | ||
action_prefix(options) + RecordIdentifier.singular_class_name(record) + routing_type(options), record_or_hash | ||
) | ||
end | ||
end | ||
|
||
def polymorphic_path(record_or_hash, url_writer) | ||
polymorphic_url(record_or_hash, url_writer, :routing_type => :path) | ||
end | ||
|
||
%w( edit new formatted ).each do |action| | ||
module_eval <<-EOT | ||
def #{action}_polymorphic_url(record_or_hash, url_writer) | ||
polymorphic_url(record_or_hash, url_writer, :action => "#{action}") | ||
end | ||
def #{action}_polymorphic_path(record_or_hash, url_writer) | ||
polymorphic_url(record_or_hash, url_writer, :action => "#{action}", :routing_type => :path) | ||
end | ||
EOT | ||
end | ||
|
||
|
||
private | ||
def action_prefix(options) | ||
options[:action] ? "#{options[:action]}_" : "" | ||
end | ||
|
||
def routing_type(options) | ||
"_#{options[:routing_type] || "url"}" | ||
end | ||
|
||
def extract_record(record_or_hash) | ||
record_or_hash.is_a?(Hash) ? record_or_hash[:id] : record_or_hash | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.