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
9 # Returns the path to the given folder.
10 # Link to self determines wether every part of the path links to itself.
11 def path(folder, link_to_self, html = true)
12 # the base url for a path is always the same:
13 url = url_for(:controller => 'folder', :action => 'list', :id => nil)
15 # start with the deepest folder and work your way up
20 # get the folders until folder doesn't have a parent anymore
21 # (you're working your way up now)
22 until folder.parent == nil
23 folder = folder.parent
24 path = folder.name + "/" + path
27 # Finally, make it a link...
29 path = '<a href="' + url + '/' + id + '">' + h(path) + '</a>'
34 # get the folders until folder doesn't have a parent anymore
35 # (you're working your way up now)
36 until folder.parent == nil
37 folder = folder.parent
38 path = '<a href="' + url + '/' + folder.id.to_s + '">' + h(folder.name) + '</a> » ' + path