Created
July 17, 2012 04:27
-
-
Save kkosuge/3127114 to your computer and use it in GitHub Desktop.
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
module ApplicationHelper | |
def link_to_with_human_readable(*args) | |
if args.size == 1 and args.first.is_a? ActiveRecord::Base | |
model = args.first | |
attributes = model.class.columns.map(&:name) | |
[:name, :title].each do |attr| | |
next unless attributes.include? attr.to_s | |
return link_to_without_human_readable(model.__send__(attr), model) | |
end | |
end | |
link_to_without_human_readable(args) | |
end | |
alias_method_chain :link_to, :human_readable | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment