Continuous data in a Rails application

I am working on the analytics page for a rails application. On the analytics page, no data is saved (this is very primitive at the moment), but it uses metrics that I grab from the database (via aggregated expressions built into ActiveRecord). In addition to collecting and presenting indicators, the only other requirement that I have is to give the user the ability to specify a date range for filtering data. Until now, I have used instance variables, etc. To store information about metrics ... as the number of indicators grows, along with the need to manage the start and end dates of filtering. I am starting to think that I should put this data in my own model. If I translate all my β€œdata” into a model, should I just use a simple object with attr_accessors or is there a more suitable base class that I could use for mutable data? I am familiar enough with MVC architecture to know that my controller is getting bloated, but not familiar enough with rails to determine how I should organize my data / logic in this case.

Any understanding would be greatly appreciated!

+3
source share
3 answers

It looks like you can use the Rails inactive write model. There's a good Railscast about it:

http://railscasts.com/episodes/121-non-active-record-model

Hope this helps,

+7
source

You are on the right track. Many applications have classes within applications / models that do not inherit from ActiveRecord :: Base. Each time you discover that you are managing a variety of arbitrary variables within controller actions, this is a good place to consider abstracting this data into a fickle model.

+2
source

Is this an area that is not currently documented, probably because ActiveRecord is sexier?

I went through the same process, finding that my actions with the controller became uncomfortably large and full of logic, when I tried to build my derived data from models based on ActiveRecord, which, in turn, began to acquire additional responsibilities, want or need.

As soon as I got the same advice that you are getting now , it all simplified superbly.

0
source

All Articles