3 Replies Latest reply on Aug 20, 2012 10:42 AM by Jon Tara

    2 controllers in one model?

      Can we have 2 controllers in one model?If yes,can anyone tell me how to do it

       

       

      Thanks,

      Divyansh

        • Re: 2 controllers in one model?
          Jon Tara

          Well, first of all, a controller is not "in" a model. A controller is a controller. A model is a model.

           

          Rhodes generates some simple boilerplate code for your when you generate a model. Rhodes assume that you want a controller to go with the model, and it builds simple CRUD templates to go along, which assume that the model and controller go together.

           

          Instead of asking whether you can have 2 controllers in one model, tell us what it is you are trying to do.

           

          You can access a model from any controller.

            • Re: 2 controllers in one model?

              I want to have two different controllers cz i want to store to different databases and want to acess them through the same model

                • Re: 2 controllers in one model?
                  Jon Tara

                  I'm not exactly sure what you mean when you say you want to store to different databases. You mean two physically separate databases in the same device? I'm not sure that Rhodes provides a way to do that.

                   

                  In any case, you are free to add any methods you would like to any model. So, you could add methods to some model to store in a different database.

                   

                  A model is nothing more than a Ruby class. It inherits functionality from Rhodes that lets you do basic operations with a single table in a single database. But you can add anything else you'd like to it.

                   

                  A controller is nothing but an endpoint for accesses to the server in Rhodes. Again, you can put any functionality you'd like in any controller. So, if you have a Location controller and a People controller, the Location controller handles requests that go to /app/Location, and the People controller handles requests that go to /app/People. You can see that you really don't ever need more than a single controller in your appliction, and the different controllers are just a convenient way to organize things.

                   

                  You are telling me how you want to accomplish something, but you are not saying what you want to accomplish. As such, it is difficult to help with specifics.