Aitor Fernández, Freelance Web Design and Programmer, Graphic Design.

Please select the below option that you would like to see

Management Enerpal documentary ⁄ Code

October 1st, 2008 at 10:34AM
screenshot Management Enerpal documentary
Read Description and View Code •  back

Sketches and part of the code that is used for intranet and document management of the company Enerpal.

Part of the code that generates dynamically navigating sections. In Enerpal Documentary use a acts_as_nested set. A nested set is a smart way to implement an ordered tree that allows for fast, non-recursive queries.


        # Methods added to this helper will be available to all templates in the application.
        module ApplicationHelper
          
          def tree_select( acts_as_tree_set, init = true, &block )
            if acts_as_tree_set.size > 0
              ret = ''
        
              acts_as_tree_set.collect do |item|
                next if item.parent_id && init
                ret += '<option value="' + item.id.to_s + '">'
                ret += item.level.to_s + ' -' + ( '-' * item.level ).to_s + ' '
                ret += yield item
                ret += '</option>'
                ret += tree_select( item.children, false, &block ) if item.children.size > 0
              end
              
              ret += ''
            end
        
          end
          
          def tree_ul( acts_as_tree_set, init = true, &block )
            if acts_as_tree_set.size > 0
              ret = '<ul>'
        
              acts_as_tree_set.collect do |item|
                next if item.parent_id && init
                ret += '<li>'
                ret += yield item
                ret += tree_ul( item.children, false, &block ) if item.children.size > 0
                ret += '</li>'
              end
        
              ret += '</ul>'
            end
          end
        
        end
        
        # Example for SchemesViews
        <h3>Rails UL Helper for acts_as_tree</h3>
        <%= tree_ul( @schemes ) { |item| 
                        "#{item.name} [ c r u #{link_to 'd', scheme_path( item ), :confirm => 'Sure?', :method => :delete } ] 
                         #{ link_to 'add document', new_scheme_document_path( item ) if item.children_count.zero? }
                         #{ tell_me_documents( item ) unless item.documents.empty? }" } %>
        
        
Tag Filed under: Code
Icon-com Commentaries about Management Enerpal documentary: Click here