1 # Global helper methods for views
2 module ApplicationHelper
3 # Replace 'name' with 'username' in a message
4 def name_to_username(msg)
5 return msg.sub('Name', 'Username') if msg
8 # Returns the path to the given folder.
9 # Link to self determines wether every part of the path links to itself.
10 def path(folder, link_to_self)
11 # the base url for a path is always the same:
12 url = url_for(:controller => 'folder', :action => 'list', :id => nil)
14 # start with the deepest folder and work your way up
19 # get the folders until folder doesn't have a parent anymore
20 # (you're working your way up now)
21 until folder.parent == nil
22 folder = folder.parent
23 path = folder.name + "/" + path
26 # Finally, make it a link...
27 path = '<a href="' + url + '/' + id + '">' + h(path) + '</a>'
31 # get the folders until folder doesn't have a parent anymore
32 # (you're working your way up now)
33 until folder.parent == nil
34 folder = folder.parent
35 path = '<a href="' + url + '/' + folder.id.to_s + '">' + h(folder.name) + '</a> » ' + path