I would like to set up a global variable to count how many times a specific method is executed, but I would like the variable to keep counting regardless of sessions, restarting the app, etc. Is this possible? Or... I could just do a simple read/write to a text file on the server, but I''m not finding any good tutorials or examples about simple text i/o... any suggestions? Thanks! -stirman -- Posted via http://www.ruby-forum.com/.
you could create another table with one record that you load and increase using the rails Find and Save methods for the Model. On 6/19/06, Jason Stirman <stirman@gmail.com> wrote:> I would like to set up a global variable to count how many times a > specific method is executed, but I would like the variable to keep > counting regardless of sessions, restarting the app, etc. Is this > possible? > > Or... I could just do a simple read/write to a text file on the server, > but I''m not finding any good tutorials or examples about simple text > i/o... any suggestions? > > Thanks! > -stirman > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Seems like a lot of cpu time and effort increase an int variable, right? Or would text file i/o be comparable? Thanks for the suggestion, I appreciate it! -stirman> you could create another table with one record that you load and > increase using the rails Find and Save methods for the Model.-- Posted via http://www.ruby-forum.com/.
It will take as much time, probably less, to update a field in the database than to update and save to a file by hand. Besides, is the site going to be that busy that you need to take into account system resources? Jason Jason Stirman wrote:> Seems like a lot of cpu time and effort increase an int variable, right? > > Or would text file i/o be comparable? > > Thanks for the suggestion, I appreciate it! > > -stirman > > >> you could create another table with one record that you load and >> increase using the rails Find and Save methods for the Model. >> > > >
I agree using a table/record is the best approach. But if you really want to use a file, then use the IO.File class in Ruby to open/read/write the file. For details look here: http://ruby.outertrack.com/class/IO -- "Impossible is nothing." -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060619/77301bbd/attachment.html
On 6/19/06, Jason Stirman <stirman@gmail.com> wrote:> Seems like a lot of cpu time and effort increase an int variable, right? > > Or would text file i/o be comparable?Nice thing about the database method is if you put a bit ''o metadata in there you can use the same ActiveRecord model for incrementing other stuff. It will likely come down the pipes anyway... :) I use a similar mechanism to track "ad" impressions / hits... :: shrug :: Performance is fine. -Curtis