Hi! We are a group of developers from Argentina. We discovered rails (and Ruby) thanks to Dave Thomas blog. We thougt it was an interesting idea y decided to investigate it a bit more. We followed the tutorials (specially the very nice one about a todo list), and we enjoyed very much rails simplicity and power so we decided to try and write an example application to learn more about the framework. We have a doubt about the controller. We found out that each time an action is invoked, a new instance of the controller is created. Is there a way of keeping the same controller instance between actions invocations? If this is not posible, is there a place where we can keep alive some objects between these invocations other than the @session array? Thank you very much, and please forgive my english (I haven´t write in a while...) --------------------------------- Do You Yahoo!? Todo lo que quieres saber de Estados Unidos, América Latina y el resto del Mundo. Visíta Yahoo! Noticias. _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
> We have a doubt about the controller. We found out that each time an > action is invoked, a new instance of the controller is created. Is > there a way of keeping the same controller instance between actions > invocations? If this is not posible, is there a place where we can > keep alive some objects between these invocations other than the > @session array?There isn''t a way to keep controllers alive between requests. And there isn''t a way to share objects outside of the @session array (or integration with other remote services, like mmcache). This is by the design known as "Shared Nothing", which is the same approach PHP and others use to be able to scale somewhat effortlessly just by adding more boxes. You push all the stuff that needs to be shared between requests off to the database or a remote service (like drb) and then you can just add new application boxes as you please.> Thank you very much, and please forgive my english (I haven´t write > in a while...)No sweat. Welcome to the community. -- David Heinemeier Hansson, http://www.basecamphq.com/ -- Web-based Project Management http://www.rubyonrails.org/ -- Web-application framework for Ruby http://macromates.com/ -- TextMate: Code and markup editor (OS X) http://www.loudthinking.com/ -- Broadcasting Brain
On Tue, 21 Dec 2004 18:55:18 +0100, David Heinemeier Hansson <david-OiTZALl8rpK0mm7Ywyx6yg@public.gmane.org> wrote:> > We have a doubt about the controller. We found out that each time an > > action is invoked, a new instance of the controller is created. Is > > there a way of keeping the same controller instance between actions > > invocations? If this is not posible, is there a place where we can > > keep alive some objects between these invocations other than the > > @session array? > > There isn''t a way to keep controllers alive between requests. And there > isn''t a way to share objects outside of the @session array (or > integration with other remote services, like mmcache). > > This is by the design known as "Shared Nothing", which is the same > approach PHP and others use to be able to scale somewhat effortlessly > just by adding more boxes. You push all the stuff that needs to be > shared between requests off to the database or a remote service (like > drb) and then you can just add new application boxes as you please. > > > Thank you very much, and please forgive my english (I haven´t write > > in a while...) > > No sweat. Welcome to the community. > -- > David Heinemeier Hansson, > http://www.basecamphq.com/ -- Web-based Project Management > http://www.rubyonrails.org/ -- Web-application framework for Ruby > http://macromates.com/ -- TextMate: Code and markup editor (OS X) > http://www.loudthinking.com/ -- Broadcasting Brain > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >David, What of session-less controllers that don''t need to be recreated? This still allows a share-nothing architecture. Regards, Nick -- Nicholas Van Weerdenburg
> What of session-less controllers that don''t need to be recreated? This > still allows a share-nothing architecture.Action Controller makes liberal use of session variables, so it''s a no go in any case. Besides, I doubt there''s a whole lot of speed to be gained from the experience. -- David Heinemeier Hansson, http://www.basecamphq.com/ -- Web-based Project Management http://www.rubyonrails.org/ -- Web-application framework for Ruby http://macromates.com/ -- TextMate: Code and markup editor (OS X) http://www.loudthinking.com/ -- Broadcasting Brain
On Tue, 21 Dec 2004 19:16:23 +0100, David Heinemeier Hansson <david-OiTZALl8rpK0mm7Ywyx6yg@public.gmane.org> wrote:> Action Controller makes liberal use of session variables, so it''s a no > go in any case. Besides, I doubt there''s a whole lot of speed to be > gained from the experience.I agree---the class definitions themselves _are_ cached between requests (assuming you are runnig your production server with the recommended configuration), and it''s this file IO and parsing that generates the most overhead. Creating a new controller instance on each request is a very small overhead, and changing the behavior would be a lot of work for very little gain. Lorenzo, Is there something you''re trying to accomplish that causes you to think you need this behavior? If so, let us know---the people on this list are very helpful, and perhaps we could help you figure out an alternative method to accomplish what you want. -- Regards, John Wilger ----------- Alice came to a fork in the road. "Which road do I take?" she asked. "Where do you want to go?" responded the Cheshire cat. "I don''t know," Alice answered. "Then," said the cat, "it doesn''t matter." - Lewis Carrol, Alice in Wonderland
I am amazed with the fast responses!! Thank you all very much. We wanted to keep some objects state between the calls because we don´t have yet a need for a database, and we were trying to keep everything in memory (we are developing the app incrementally and it''s easier to change the design when you aren''t tied to a database). May be the solution would be to have persistance with a different aproach... Thanks, Lorenzo. John Wilger <johnwilger-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: On Tue, 21 Dec 2004 19:16:23 +0100, David Heinemeier Hansson wrote:> Action Controller makes liberal use of session variables, so it''s a no > go in any case. Besides, I doubt there''s a whole lot of speed to be > gained from the experience.I agree---the class definitions themselves _are_ cached between requests (assuming you are runnig your production server with the recommended configuration), and it''s this file IO and parsing that generates the most overhead. Creating a new controller instance on each request is a very small overhead, and changing the behavior would be a lot of work for very little gain. Lorenzo, Is there something you''re trying to accomplish that causes you to think you need this behavior? If so, let us know---the people on this list are very helpful, and perhaps we could help you figure out an alternative method to accomplish what you want. -- Regards, John Wilger ----------- Alice came to a fork in the road. "Which road do I take?" she asked. "Where do you want to go?" responded the Cheshire cat. "I don''t know," Alice answered. "Then," said the cat, "it doesn''t matter." - Lewis Carrol, Alice in Wonderland _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails --------------------------------- Do You Yahoo!? Todo lo que quieres saber de Estados Unidos, América Latina y el resto del Mundo. Visíta Yahoo! Noticias. _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
> We wanted to keep some objects state between the calls because we > don´t have yet a need for a database, and we were trying to keep > everything in memory (we are developing the app incrementally and it''s > easier to change the design when you aren''t tied to a database). May > be the solution would be to have persistance with a different > aproach...Sounds like you might be looking for Madeleine, which is what Instiki (a wiki based on a very early version of Action Pack) uses. You can grab it off http://madeleine.sourceforge.net/ Beware that you''ll need to put this in a DRb service (read more about that in the standard library) unless you''re using WEBrick. Otherwise, you could just start out using SQLite, which is very light-weight and doesn''t require you to run a server. -- David Heinemeier Hansson, http://www.basecamphq.com/ -- Web-based Project Management http://www.rubyonrails.org/ -- Web-application framework for Ruby http://macromates.com/ -- TextMate: Code and markup editor (OS X) http://www.loudthinking.com/ -- Broadcasting Brain
Lorenzo, One of the design features of rails is to use introspection on the database, enabling a lot of flexibility during development. This allows changes to the databases to be reflected into the running application without any or much coding. In this way, the database because part of the application modeling technique, rather then just a pain you need to implement for persistence. It''s backwards from what I''m used to- the database being generated from the programming code. However, it seems fairly effective. I expect you may loose more then you gain by avoiding the database. Bottom line- the rules of Java don''t apply here :). Similarly, the rules of most frameworks don''t apply here. There are very few configuration files and little of the traditional effort and verbosity required in using a persistence layer. And if you want a really light-weight, embeddable, low maintenance database, try sqllite. Regards, Nick On Tue, 21 Dec 2004 13:35:44 -0600 (CST), Lorenzo Jorquera <lorenzo_jorquera-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> I am amazed with the fast responses!! Thank you all very much. > > We wanted to keep some objects state between the calls because we don´t have > yet a need for a database, and we were trying to keep everything in memory > (we are developing the app incrementally and it''s easier to change the > design when you aren''t tied to a database). May be the solution would be to > have persistance with a different aproach... > > Thanks, Lorenzo. > > > > > John Wilger <johnwilger-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > On Tue, 21 Dec 2004 19:16:23 +0100, David Heinemeier Hansson > wrote: > > Action Controller makes liberal use of session variables, so it''s a no > > go in any case. Besides, I doubt there''s a whole lot of speed to be > > gained from the experience. > > I agree---the class definitions themselves _are_ cached between > requests (assuming you are runnig your production server with the > recommended configuration), and it''s this file IO and parsing that > generates the most overhead. Creating a new controller instance on > each request is a very small overhead, and changing the behavior would > be a lot of work for very little gain. > > Lorenzo, > > Is there something you''re trying to accomplish that causes you to > think you need this behavior? If so, let us know---the people on this > list are very helpful, and perhaps we coul d help you figure out an > > alternative method to accomplish what you want. > -- > Regards, > John Wilger > > ----------- > Alice came to a fork in the road. "Which road do I take?" she asked. > "Where do you want to go?" responded the Cheshire cat. > "I don''t know," Alice answered. > "Then," said the cat, "it doesn''t matter." > - Lewis Carrol, Alice in Wonderland > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > ________________________________ > Do You Yahoo!? > Todo lo que quieres saber de Estados Unidos, América Latina y el resto del > Mundo. > Visíta Yahoo! Noticias. > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- Nicholas Van Weerdenburg
On Tue, 21 Dec 2004, Lorenzo Jorquera wrote:> We wanted to keep some objects state between the calls because we > don''t have yet a need for a database....Oops. Now you need a database. :-) Note, though, that this does not mean you need to install Oracle. ActiveRecord support SQLite, which sounds to me like it would do just what you need: in-memory storage of data shared between requests. cjs -- Curt Sampson <cjs-gHs2Wiolu3leoWH0uzbU5w@public.gmane.org> +81 90 7737 2974 http://www.NetBSD.org Make up enjoying your city life...produced by BIC CAMERA
On Tue, 21 Dec 2004, Nicholas Van Weerdenburg wrote:> It''s backwards from what I''m used to- the database being generated > from the programming code.Let me chant again, in the hope that this idea will be picked up one day: The schema for the DBMS *is* programming code. There is little difference between CREATE TABLE bar (foo_id PRIMARY KEY REFERENCES foo) and class Foo has_many :bar end You can refactor by changing one to the other, assuming you''ve extended your agile methods enough that you cover your database DDL as well as your Ruby or Java or Smalltalk or what-have-you. cjs -- Curt Sampson <cjs-gHs2Wiolu3leoWH0uzbU5w@public.gmane.org> +81 90 7737 2974 http://www.NetBSD.org Make up enjoying your city life...produced by BIC CAMERA
Thank you to all that suggested solutions. This list is terrific!! Yesterday (one of our two weekly meeting days) we decided that we will keep the object we need in the session data for this iteration (we don´t need persistance yet and the data we want to keep is small). Next iteration we will probably begin to use a db... Lorenzo. Curt Sampson <cjs-gHs2Wiolu3leoWH0uzbU5w@public.gmane.org> wrote: On Tue, 21 Dec 2004, Lorenzo Jorquera wrote:> We wanted to keep some objects state between the calls because we > don''t have yet a need for a database....Oops. Now you need a database. :-) Note, though, that this does not mean you need to install Oracle. ActiveRecord support SQLite, which sounds to me like it would do just what you need: in-memory storage of data shared between requests. cjs -- Curt Sampson +81 90 7737 2974 http://www.NetBSD.org Make up enjoying your city life...produced by BIC CAMERA _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails --------------------------------- Do You Yahoo!? Todo lo que quieres saber de Estados Unidos, América Latina y el resto del Mundo. Visíta Yahoo! Noticias. _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails