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?
class AppStateController < Rho::RhoController
Then in my other controllers:
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.