Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def link_to_active_if(condition, link_title, link_path={}, opts={})
- if condition
- classes = opts.delete(:class) || ""
- classes.rstrip!
- # checking to see if "active" is already one of the classes assigned, and if NOT, append it to the classes string (sorry, Ruby 1.8 doesn't support negative lookbehind)
- unless classes =~ /^(\w*\s+)*active(?!\w)/
- if classes.blank?
- classes = 'active'
- else
- classes << " active"
- end
- end
- end
- old_opts = opts.dup
- link_to_if(condition, link_title, link_path, opts.merge({:class => classes})){
- link_to(link_title, link_path, old_opts)
- }
- end
Add Comment
Please, Sign In to add comment