Skip to content

Instantly share code, notes, and snippets.

@BaylorRae
Created August 31, 2012 21:46
Show Gist options
  • Save BaylorRae/3559583 to your computer and use it in GitHub Desktop.
Save BaylorRae/3559583 to your computer and use it in GitHub Desktop.
def link_to_with_notifications(*args, &block)
# get notification count from hash
notifications = args[2][:notifications] || 0
# create the data- attribute unless notifications.zero?
args[2]['data-notifications'] = notifications unless notifications.zero?
# delete original notifications hash
args[2].delete(:notifications)
# run original link_to helper
link_to(*args, &block)
end
<%= link_to_with_notifications 'Completed Orders',
user_carts_path(user, view: 'completed'),
class: 'button',
notifications: user.shopping_carts.where('completed = ?', true).count %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment