Created
April 4, 2014 05:21
-
-
Save awesome/9968623 to your computer and use it in GitHub Desktop.
quite hacky to say the least, but it's how I get my kicks…
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 | |
# @see https://github.com/rails/journey | |
def link(txt, ctl, act) | |
begin | |
x = Rails.application.routes.routes.select {|x| x.defaults[:controller] == ctl and x.defaults[:action] == act}.first.path.spec.left.to_s | |
return link_to(txt.html_safe, x) | |
rescue => e | |
message = "ERROR route does not exist; controller: #{ctl}, action: #{act}; #{e.message}" | |
# log | |
Rails.logger.error(message) | |
# raise (not graceful) | |
raise message | |
# or return (graceful) | |
return nil | |
end | |
end | |
end | |
# in the view | |
link('dude awesome', 'controller_name', 'action_name') | |
#=> <a href="/controller/action_name">dude awesome</a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment