# How do I organize my model code?

**URL:** <https://www.ruby-forum.com/t/how-do-i-organize-my-model-code/162504>\
**Category:** Rails\
**Created:** [March 10, 2009, 4:25pm UTC](https://www.ruby-forum.com/t/how-do-i-organize-my-model-code/162504 "2009-03-10T16:25:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![davox](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/90ced4/32.png) [@davox](https://www.ruby-forum.com/u/davox)\
**Post date:** [March 10, 2009, 4:25pm UTC](https://www.ruby-forum.com/t/how-do-i-organize-my-model-code/162504/1 "2009-03-10T16:25:13Z")

</div>

I have a basic question. I’ve been working with Rails for a couple  
months now, and I’ve read the O’Reilly book on it, but once I started  
making a basic sized application, it seems like my main model “List” has  
waaay too much code, and I want to break it down into classes and  
subclasses.

Most of the code in “List” is for HTML parsing, so as a first step, I  
would want to make a class “Parser” that is accessible to “List.”

But I have so many questions about how to create this new class:

Where do I put “Parser”?

- In “List” as another class?  
Is OOP in Rails only centered around database objects?
- Would I have to make a “Parser” model?
  - Even if there’s no DB table for “Parser”?  
Is there any guide to Rails best programming practices?

Thanks,  
David

---

<div class="post-metadata">

**Author:** ![davox](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/90ced4/32.png) [@davox](https://www.ruby-forum.com/u/davox)\
**Post date:** [March 10, 2009, 8:18pm UTC](https://www.ruby-forum.com/t/how-do-i-organize-my-model-code/162504/2 "2009-03-10T20:18:23Z")

</div>

David D. wrote:

> I have a basic question. I’ve been working with Rails for a couple  
> months now, and I’ve read the O’Reilly book on it, but once I started  
> making a basic sized application, it seems like my main model “List” has  
> waaay too much code, and I want to break it down into classes and  
> subclasses.
> 
> Most of the code in “List” is for HTML parsing, so as a first step, I  
> would want to make a class “Parser” that is accessible to “List.”
> 
> But I have so many questions about how to create this new class:
> 
> Where do I put “Parser”?
> 
> - In “List” as another class?  
> Is OOP in Rails only centered around database objects?
> - Would I have to make a “Parser” model?
> - Even if there’s no DB table for “Parser”?  
> Is there any guide to Rails best programming practices?
> 
> Thanks,  
> David

I would suggest starting with reading Object Thinking by David West  
([http://www.microsoft.com/learning/en/us/books/6820.aspx](http://www.microsoft.com/learning/en/us/books/6820.aspx)) This may help  
you to build your objects out.

You can have objects that don’t extend ActiveRecord::Base, just make a  
new class, and call it whatever you want. Place that file into the  
models folder.

Just stick to conventions and make your code work first, then go back  
and refactor. Make lots of tests, and you will be fine.

~Jeremy

---

<div class="post-metadata">

**Author:** ![davox](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/90ced4/32.png) [@davox](https://www.ruby-forum.com/u/davox)\
**Post date:** [March 11, 2009, 6:22pm UTC](https://www.ruby-forum.com/t/how-do-i-organize-my-model-code/162504/3 "2009-03-11T18:22:35Z")

</div>

Jeremy W. wrote:

> I would suggest starting with reading Object Thinking by David West  
> ([http://www.microsoft.com/learning/en/us/books/6820.aspx](http://www.microsoft.com/learning/en/us/books/6820.aspx)) This may help  
> you to build your objects out.
> 
> You can have objects that don’t extend ActiveRecord::Base, just make a  
> new class, and call it whatever you want. Place that file into the  
> models folder.
> 
> Just stick to conventions and make your code work first, then go back  
> and refactor. Make lots of tests, and you will be fine.
> 
> ~Jeremy

Thank you!
