# Extract Class and Rails model objects

**URL:** <https://www.ruby-forum.com/t/extract-class-and-rails-model-objects/123677>\
**Category:** Rails\
**Created:** [December 19, 2007, 6:17pm UTC](https://www.ruby-forum.com/t/extract-class-and-rails-model-objects/123677 "2007-12-19T18:17:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ratcheer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/aca169/32.png) [@ratcheer](https://www.ruby-forum.com/u/ratcheer)\
**Post date:** [December 19, 2007, 6:17pm UTC](https://www.ruby-forum.com/t/extract-class-and-rails-model-objects/123677/1 "2007-12-19T18:17:50Z")

</div>

Do you ever break up a large rails model class into smaller classes for  
the  
sake of just having smaller classes?

I have a user model class that is growing in number of attributes quite  
quickly. A part of me thinks I should group attributes together and  
peel  
them off as separate classes in order to reduce the number of attributes  
in  
the user class, another part of me says that the extra work to create  
and  
maintain a separate table plus the has-one/belongs\_to relationship makes  
it  
so doing this just isn’t worth it. I don’t have any problems using this  
class, it’s just the growing number of attributes and instance methods  
is  
approaching 50, and it just smells funny.

Do you do anything about this?

---

<div class="post-metadata">

**Author:** ![ratcheer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/aca169/32.png) [@ratcheer](https://www.ruby-forum.com/u/ratcheer)\
**Post date:** [December 19, 2007, 6:43pm UTC](https://www.ruby-forum.com/t/extract-class-and-rails-model-objects/123677/2 "2007-12-19T18:43:15Z")

</div>

One thing you can do is extract “like” methods into separate modules and  
then include the modules in the class. Other than that, I am not sure.

---

<div class="post-metadata">

**Author:** ![ratcheer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/aca169/32.png) [@ratcheer](https://www.ruby-forum.com/u/ratcheer)\
**Post date:** [December 19, 2007, 7:41pm UTC](https://www.ruby-forum.com/t/extract-class-and-rails-model-objects/123677/3 "2007-12-19T19:41:17Z")

</div>

Tim C. wrote:

> Do you ever break up a large rails model class into smaller classes for

> Do you do anything about this?

Well, in some government forms, i could have 100 fields in a table.

break up if there are the needs for one to many.  
or you can do a ONE TO ONE for a group a data  
that is not always used.

or you can just show PIECES of a data, at a time.  
break it up in forms.

or… you can do lunch.

i vote for lunch…

---

<div class="post-metadata">

**Author:** ![ratcheer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/aca169/32.png) [@ratcheer](https://www.ruby-forum.com/u/ratcheer)\
**Post date:** [December 19, 2007, 9:16pm UTC](https://www.ruby-forum.com/t/extract-class-and-rails-model-objects/123677/4 "2007-12-19T21:16:54Z")

</div>

looks like  
composed\_of[http://api.rubyonrails.org/classes/ActiveRecord/Aggregations/ClassMethods.html#M001344](http://api.rubyonrails.org/classes/ActiveRecord/Aggregations/ClassMethods.html#M001344)might  
be worth a look…

On Dec 19, 2007 10:41 AM, gemblon (t.b.)  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![ratcheer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/aca169/32.png) [@ratcheer](https://www.ruby-forum.com/u/ratcheer)\
**Post date:** [December 20, 2007, 12:33am UTC](https://www.ruby-forum.com/t/extract-class-and-rails-model-objects/123677/5 "2007-12-20T00:33:06Z")

</div>

Depends on what you would define as “large”. I have a 600+ line model  
here  
that runs fine.

On Dec 20, 2007 6:45 AM, Tim C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > Do you ever break up a large rails model class into smaller classes

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!
