2 Replies Latest reply on Jul 25, 2013 4:02 AM by David Miller

    Architecting Rho and MVC

    David Miller

      I have a conundrum.

       

      I have 4 models associated with my app.  3 are true database type models to store Inventory, Products and Item data.  However the remaining model is a PropertyBag to store application related information such as the current state.  The reason I have utilised a model for storing application state is that I need to maintain the state even if the users delete the app, turn off the device, etc and I also need to transfer/sync that state to a server.  I also wanted a device independent method for this and a model seems like the most suitable mechanism.  I considered Globals, cookies, localStorage but none were entirely suitable especially when considering the sync capability of models.

       

      Consequently I need to access the application state model very frequently within the application flow.  This is causing issues such as speed but mostly a headache trying to get from one model to the other.

       

      Considering I can navigate with :

           url_for (view to any controller)

           render (a view associated with a controller)

           redirect (to any view from a controller)

           Controller to controller (with method calls?)

       

      …all should be easy right?  But it's not considering parameter passing, accessor methods and the MVC paradigm causing me general grief.

       

      So I thought about making the application state aspect a utility.  I mean 'require' it in my other controllers so it's easy to access.  The question is, since you have to define it as a 'module' then 'require' it in those other controllers, my application_state controller is a class, can this be done?

       

      I.e. Would this work?

       

      application_state_controller.erb:

       

      module application_state

      require 'rho/rhocontroller'

      require 'helpers/browser_helper'

      class AppStateController < Rho::RhoController

        include BrowserHelper

       

        def..

       

       

      Then in my other controllers:

       

      require 'app/application_state_controller.erb'

       

      I would imagine I'd have to 'require' the AppState.rb too.

       

      Any thoughts on architecting this, including if I'm mad to attempt it, offers of a better way or whatever.  Actually, having just re-read this, I think it is a silly idea.  But I'd appreciate any wise words anyway

      Note: my Rails experience is not that strong.

        • Re: Architecting Rho and MVC
          Kutir Mobility

          Hi David,

          You can use the below syntax in controller for navigation

          redirect :controller => :Customer, :action => :index

          WebView.navigate(url, index)

          Steps for creating "module" in rhodes apps

          Examples:

          1. Create/Add application_state.rb file in helpers folder

          2. Write your code in application_state.rb.

              Eg:

          module ApplicationState

            def method1

            end

           

            def method2

            end

          end

          3. Use "ApplicationState" module method in another controller as shown below,

              Eg:product.rb

          require 'rho/rhocontroller'

          require 'helpers/browser_helper'

          require 'helpers/application_state'

           

           

          class ProductController < Rho::RhoController

            include BrowserHelper

            include GeoHelper

          end

           

           

          Let me know if that helps

           

          Visnupriya R

          Kutir Mobiltiy

            • Re: Architecting Rho and MVC
              David Miller

              Not really.  I'm comfortable with creating utility modules.  I was referring to creating utility models.

               

              However, I think I have solved it now.  I have turned the application upside-down and made the ApplicationState controller the main controller that supports the application flow.  Then all other controllers are considered lower order controllers, effectively containing wrappers for CRUD operations only.

               

              The only aspect of distinction is that the ApplicationState controller has its own model attached.