3 Replies Latest reply on Feb 6, 2013 9:14 PM by Mark Nongkhlaw

    Nested loop problem

    Mark Nongkhlaw

      I have a hierarchy of models which are related (call them associations if you will) :

       

      Sectors, Sub-Sectors and Schemes

       

      Each Sector might have a number of Sub-Sectors under it. Similarly, each Sub-Sector has a number of Schemes under it.

      What I wanted was to list the Sectors, Sub-Sectors and Schemes thru a loop in my ERB as follows :

       

      <div data-role="content">  

            <ul data-role="listview">

            <% @sectors.each do |sector| %>

              <li>

                   <b><u>SECTOR : <%= sector.sector_name %></b></u><BR><BR>

                    <% @subsectors.each do |subsector| %>

                      <b><u><%= "SUB-SECTOR : "+subsector.sub_sector_name+"<BR>" if subsector.sector_code == sector.sector_code %></b></u>

                      <% @schemes.each do |scheme| %>

                        <%= scheme.scheme_name+"<BR><BR>" if ((scheme.sector_code == sector.sector_code) && (scheme.sub_sector_code == subsector.sub_sector_code))  %>     

                        <% end %>

                     <% end %>

                   <% end %>

               </li>

             </ul>

         </div>

       

      My controller is very simple :

       

      def index

          @sectors = Sector.find(:all)   

          @subsectors = Subsector.find(:all)

          @schemes = Scheme.find(:all)  

          render :back => '/app'     

        end

       

      My view renders as expected in Android SGS2 device, but the app exits when trying to load the view in a WM device with relatively lesser memory.

      How can I improve the above code to make it more efficient?

        • Re: Nested loop problem
          Mark Nongkhlaw

          This is what the output should look like (got it from Rhosimulator). Is it too much for device to process?

           

          SECTOR : AGRICULTURE AND ALLIED

           

           

          SUB-SECTOR : AGRICULTURE

          Integrated Agriculture Development in NER

           

           

          Establishment of Cold Storage Units in NER

           

           

          Diversification of Agronomical Crops

           

           

          Support for Tissue Culture Laboratories in NER

           

           

          SUB-SECTOR : HORTICULTURE

          Development/Rejuvenation of Plantation Crops in NER

           

           

          Marketing Support to Agro-Horticulture Produces in NER

           

           

          Pilot Project for Development of Horticulture & Floriculture

           

           

          Support for extension,innovation & awareness through Research Organization & Trg. Centres

           

           

          SUB-SECTOR : FOREST AND PLANT RESOURCES

          Community Bio-diversity Conservation Project

           

           

          Schemes on development of Bamboo related activities in NER

           

           

          North Eastern Bio-diversity Research Cell, NEHU

           

           

          Preservation of Loktak Lake, Manipur

           

           

          Documentation & Preservation of Biological Diversities in NER

           

           

          All Forestry & Sericulture related Schemes under the 12th Plan of NEC

           

           

          SUB-SECTOR : ANIMAL HUSBANDRY AND VETERINARY

          Integrated Animal Husbandry Project (including production of milk, meat etc. and slaughter houses) in NE States

           

           

          Strengthening of Established seed,feed and fodder farms in NER

           

           

          SUB-SECTOR : FISHERY

          Integrated Fisheries Development Project in NER

           

           

          SUB-SECTOR : COMMUNITY DEVELOPMENT PROJECT

          Augmentation of NERCORM Project in NER

           

           

          All Community development & Livelihood Projects under implementation by State Government

           

           

          SECTOR : WATER AND POWER DEVELOPMENT

           

           

          SUB-SECTOR : POWER DEVELOPMENT

          Upgradation/Improvement/Construction of Power Transmission and Distribution Lines (132x11KVA & 133x11KVA)Sub-Stations

           

           

          21 MW Gas Thermal Project at Baramura-II, Tripura

           

           

          Assistance for implementation of small hydro power projects

           

           

          System Improvement Scheme (Transmission-Substation)

           

           

          Control of siltation of Umiam Lake

           

           

          Small/Mini Hydel Projects and Solar/Wind Energy Systems

           

           

          Renewal Resources of Energy Projects

           

           

          SUB-SECTOR : WATER DEVELOPMENT

          NERIWALM, Tezpur

           

           

          Survey & Investigation of HEP & MPP (CWC)

           

           

          Implementation of FC and RM Schemes(Chathe river bank protection,Jiadhol,Chunpura and Parherkandi Protection Works)

           

           

          Initiatives for augmentation of waterworks schemes of Sikkim

           

           

          Survey and Investigation of Hydel Project and Multipurpose Project

           

           

          Implementation of Surface Irrigation Projects

           

           

          Implementation of Flood Control and River Management

           

           

          Schemes of Sikkim

           

           

          Implementation of Watershed Management

           

           

          Load flow study of the region by PGCIL

           

           

          Provision for new schemes

           

           

          SECTOR : INDUSTRIES AND TOURISM

           

           

          SUB-SECTOR : INDUSTRIES

          Promotion of Industries and Trade in NER

           

           

          UNIDO Cane & Bamboo Technology Centre and Bamboo Technology Park

           

           

          Exposure/visit for production, display & marketing in international fairs

           

           

          Support to Look East Policy Initiative

           

           

          SEZ/Food Park/BTP etc.

           

           

          Support to Pilot Plastic Parks

           

           

          Cluster Development:Marketing support to Industry

           

           

          SUB-SECTOR : TOURISM

          Promotion of Tourism in NER

           

           

          Support to Infrastructure Leasing & Financial Services(IL&FS)

           

           

          Renovation of Inspection Bungalows, Tourist Lodges,Guest Houses etc.

           

           

          Development of Inter-State Tourist Circuit

           

           

          Capacity Building : Promotion of NE Tourist Operators/Guides etc.

           

           

          Development of Adventure Tourism, Tea Tourism, Historical/War & Village Tourism etc.

           

           

          Assistance for capacity building programmes in the Tourism sector

           

           

          SECTOR : TRANSPORT AND COMMUNICATION

           

           

          SUB-SECTOR : Strengthening of Airports in NER

          By AAI

           

           

          Upgradation of existing airports by AAI:S&I/Feasability studies/DPRs etc

           

           

          SUB-SECTOR : Survey and Investigation of roads and airports

          By State Government./AAI/BRO

           

           

          By NEC through professional agencies

           

           

          SUB-SECTOR : Roads and Bridges

          State PWDs

           

           

          Border Roads Organization

           

           

          Conversion of Timber Bridges into Permanent bridges

           

           

          11th Plan Regional Road Schemes in all N.E. States

           

           

          9th Plan Roads

           

           

          10th Plan Roads

           

           

          SUB-SECTOR : Interstate Bus Terminus

          Construction of Inter-State Bus Terminus/Inter-State Truck Terminus(OLD Scheme)

           

           

          Construction of Inter-State Bus Terminus/Inter-State Truck Terminus(NEW Scheme)

           

           

          SUB-SECTOR : Air Connectivity in NER

          Air Connectivity in NER (Support for 50-seater aircraft services)

           

           

          SUB-SECTOR : Housing for NEC Staff and Office

          Housing for NEC Staff and Office

           

           

          SECTOR : MEDICAL AND HEALTH

           

           

          SUB-SECTOR : Support to the Health Institutes Administered by NEC (RIMS,RIPAN,LGBRIMH)

          RIMS, Imphal

           

           

          RIPAN, Aizawl

           

           

          LGBRIMH, Tezpur

           

           

          SUB-SECTOR : Support to Other Health Institutes in NER

          Regional Dental College, Guwahati

           

           

          Regional Nursing College, Guwahati

           

           

          Sri Sankardev Netralaya, Guwahati

           

           

          Support for additional facilities in 3 medical colleges of Assam including T.B. & Respiratory Centre at AMC & construction of paying cabins in 3 medical colleges

           

           

          Dr. B. Barua Cancer Institute

           

           

          Infrastructure support to Nursing School, Imphal

           

           

          Support to J.N. Hospital, Imphal

           

           

          Accident and Trauma Centre in NER

           

           

          Establishment of Nursing College(s) on PPP Mode in NER

           

           

          Government Ayurvedic College, Guwahati

           

           

          Support to Health Scheme of Sikkim

           

           

          Support to District Hospital, Churachandpur

           

           

          Upgradation of PHC at Raga/Boa Simla, Lower Subansiri Distt.,Arunachal Pradesh

           

           

          Establishment of CT Scan facility at General Hospital,Naharlagun,Arunachal Pradesh

           

           

          Establishment of Burn Care Unit at NEMCARE Hospital, Guwahati

           

           

          Upgradation of Dr.J.K. Saikia Homeopathic Medical College, Jorhat

           

           

          Upgradation of infrastructure (Casualty Block at OT Complex) at Naga Hospital, Kohima, Nagaland

           

           

          Upgradation of infrastructure of Nursing School at Naga Hospital, Kohima, Nagaland

           

           

          Expansion of Zion Hospital, Dimapur, Nagaland

           

           

          Modernization of Bethel Medical Research Society, Kohima, Nagaland

           

           

          Upgradation of Cancer Hospital, Agartala, Tripura

           

           

          SUB-SECTOR : Support for Development/Creation of Infrastructure in Health Centres/Institutes in NER

          Support for Development/Creation of Infrastructure in Health Centres/Institutes in NER

           

           

          SUB-SECTOR : Support for purchase of medical equipment for Health Centres/Hospitals in NER

          Support for purchase of medical equipment for Health Centres/Hospitals in NER

           

           

          SUB-SECTOR : Support for upgradation/improvement in Infrastructure/Equipment in Medical Colleges/Institutes in NE

          Support for upgradation/improvement in Infrastructure/Equipment in Medical Colleges/Institutes in NE

           

           

          SECTOR : MANPOWER DEVELOPMENT

           

           

          SUB-SECTOR : NEPA

          NEPA, Umsaw, Meghalaya

           

           

          SUB-SECTOR : Manpower Development in NER

          Financial Support to Students of NER

           

           

          Misc. Training Programme

           

           

          Skill upgradation of teachers in NER

           

           

          Support for Rajiv Gandhi Girls' Hostel, New Delhi

           

           

          Support for Lilabari Pilot Training Institute

           

           

          Support for Lakhimpur College of Veterinary Science

           

           

          Support for NER Education Council (NEREC)

           

           

          Partial support for construction of Working Women's Hostel at Delhi

           

           

          Support for Teachers Training Institute through IGNOU

           

           

          Support for preparation of DPR

           

           

          Support for North East Haat in Delhi (Gandhi Smriti Darshan Samiti Complex)

           

           

          Support for Setting up of Project Formulation and Quality Management

           

           

          Promotion of Fashion Technology Programmes and Institute

           

           

          Setting up of Hostels for N.E. students in Metros

           

           

          Assistance to National Volunteers Development Scheme

           

           

          Financial Support to employment oriented courses in the ITIs of NER

           

           

          Infrastructure Development of Educational Institutions in NER

           

           

          Support for development of Social Welfare sector

           

           

          SUB-SECTOR : Development and Promotion of Sports and Youth Activities in NER

          Development & Promotion of Sports and Youth Activities in NER

           

           

          Mountaineering and Adventure Sports Institute, Arunachal Pradesh

           

           

          Chairman's Sports Award for excellence in International and National Sports Meet by Sportsmen/Sportswomen of N.E.

           

           

          Scheme for Sports Talent Search in NER

           

           

          SECTOR : SCIENCE AND TECHNOLOGY

           

           

          SUB-SECTOR : Regional Management Information System

          RMIS

           

           

          SUB-SECTOR : NESAC, Remote Sensing and Development of Communication Related Programmes

          NESAC

           

           

          SUB-SECTOR : R & D Programme inc. Consultancy,Training,S&T Applications

          Consultancy, Training, R&D Programme

           

           

          SUB-SECTOR : S&T Cell, DMS and Earthquake Related Programmes

          Disaster Management System for NER (NEC-DOS) & Earthquake Risk Evaluation/Awareness

           

           

          SUB-SECTOR : IT Application Oriented Programmes including Telemedicine

          IT Applications & related services including Telemedicine in NER

           

           

          Food, Civil Supplies and Consumer Affairs

           

           

          Automation Of Manual Inner Line Permit System in Arunachal Pradesh

           

           

          SUB-SECTOR : IT Education Programme in NER

          IT Education Programme in NER

           

           

          SUB-SECTOR : Public Awareness of Science & Technology in State Science Centres

          Public Awareness of Science & Technology Science Centres, Science Awareness Campaign etc.

           

           

          Eco-protection of Rivers/Rivulets etc at selected cities/towns of NER

           

           

          SUB-SECTOR : Application of Science & Technology

          Eco-Protection of Rivers/Rivulets at selected Cities/Towns of NER

           

           

          SUB-SECTOR : Development of Science & Technology/ICT in NER

          S&T and ICT Development in NER

           

           

          SECTOR : INFORMATION AND PUBLIC RELATIONS

           

           

          SUB-SECTOR : Regional Documentation & Information Centre

          RDIC

           

           

          SUB-SECTOR : Information and Public Relations

          Information and Public Relations

           

           

          SUB-SECTOR : Preservation & promotion of Art & Culture in NE States

          Preservation & promotion of Art & Culture in NE States

           

           

          SUB-SECTOR : Assistance for organizing Publicity/Festivals/Films etc.

          Assistance for organizing Publicity/Festivals/Films etc.

           

           

          SUB-SECTOR : Viability gap funding for establishing Tribal Museums in the NE States

          Viability gap funding for establishing Tribal Museums in the NE States

           

           

          SECTOR : EVALUATION AND MONITORING

           

           

          SUB-SECTOR : Support for Seminars & Symposium etc.

          Support for Seminars & Symposium etc.

           

           

          SUB-SECTOR : Monitoring & Evaluation of NEC Schemes

          Setting up of Project Planning & Monitoring Cell in NEC Secretariat

           

           

          SECTOR : EXTERNALLY AIDED PROJECT

           

           

          SUB-SECTOR : CRMP for Upland Areas

          CRMP for Upland Areas

            • Re: Nested loop problem
              Mark Nongkhlaw

              OK, some more info here : In my WM6.5 device, it gives :

               

              Server Error

               

              Error: failed to allocate memory

              Trace:

              (eval):18:in `concat'

              (eval):18:in `block (3 levels) in '

              (eval):17:in `each'

              (eval):17:in `block (2 levels) in '

              (eval):15:in `each'

              (eval):15:in `block in '

              (eval):12:in `each'

              (eval):12:in `'

              lib/rho/render.rb:154:in `eval_compiled_file'

              lib/rho/render.rb:154:in `render' apps/app/Scheme/scheme_controller.rb:18:in `index'

              lib/rho/rhocontroller.rb:91:in `serve'

              lib/rho/rhoapplication.rb:226:in `serve'

              lib/rho/rho.rb:829:in `serve'

               

              Before rendering the view, I kept an Alert message in the controller. The Alert message popups in WM device before the above error page. In the case of Blackberry, the Alert popup shows forever, and no errors are shown.

               

              Is there a better way to rewrite the code to optimize memory?