# Editing 2 models

**URL:** <https://www.ruby-forum.com/t/editing-2-models/127712>\
**Category:** Rails\
**Created:** [January 31, 2008, 5:36pm UTC](https://www.ruby-forum.com/t/editing-2-models/127712 "2008-01-31T17:36:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [January 31, 2008, 5:36pm UTC](https://www.ruby-forum.com/t/editing-2-models/127712/1 "2008-01-31T17:36:35Z")

</div>

Hi all,

My model:  
user has many events through statistics and registrations

registrations contains whether or not the user was on the event,  
statistics contains what he did on the event.

I think it is better to make 2 tables since I don’t need a statistics  
record if the user was not present (registration.present = 0). But  
maybe someone has an other view ont this?

I want to create a eventview (show) where an admin can enter/change  
the event data. The admin should be able to insert whether the user  
was present (with a checkbox) and if present a form is shown on the  
same row where the statistics data can be entered (minutes  
present, …).

I’m trying to edit 2 models here: statistics and registrations.

The problem is that I don’t really have a clue on where to start.

Maybe Someone can point me in the good direction?

thanks  
Stijn

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [January 31, 2008, 5:54pm UTC](https://www.ruby-forum.com/t/editing-2-models/127712/2 "2008-01-31T17:54:23Z")

</div>

Maybe you could just stick with a User and Events model. Then each  
has\_and\_belongs\_to\_many :events/:users.

-Ryan

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [January 31, 2008, 7:14pm UTC](https://www.ruby-forum.com/t/editing-2-models/127712/3 "2008-01-31T19:14:12Z")

</div>

registrations contains whether or not the user was on the event,  
statistics contains what he did on the event.

So basically,

if user was at event  
registration = yes  
statistics = data on user’s attendence  
else  
registration = no  
end

It seems like your registration model’s primary purpose is to indicate  
whether attendance occurred, thus creating the need for a statistics  
entry. Instead, you should do:

a user :has\_many :events, :through =\> :attendances

attendance will do everything that your statistics model does. more  
importantly, its _presence_ indicates that a registration occurred,  
and if it’s not there, it means that a registration has not occurred.

Regardless of whether I understood your problem or not: using models  
for join tables (HABTM :through relationships) allows you to talk as  
directly to rails about the _relationship_ between objects as you talk  
about the objects themselves. This is a powerful and widely-applicable  
concept.

Jim C.

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [January 31, 2008, 7:18pm UTC](https://www.ruby-forum.com/t/editing-2-models/127712/4 "2008-01-31T19:18:20Z")

</div>

BTW, YAML form builder:

[http://www.anup.info/2007/10/13/yaml\_form\_builder-rails-plugin/](http://www.anup.info/2007/10/13/yaml_form_builder-rails-plugin/)

will dynamically insert form markup in eRB inside your views based on  
YAML specifications. It will speed up construction, and make your  
forms quite maintainable.

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [February 5, 2008, 2:31pm UTC](https://www.ruby-forum.com/t/editing-2-models/127712/5 "2008-02-05T14:31:57Z")

</div>

thanks,

that railscastis realy helpfull

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [February 4, 2008, 2:44am UTC](https://www.ruby-forum.com/t/editing-2-models/127712/6 "2008-02-04T02:44:58Z")

</div>

check this out as well:

> **[\#73 Complex Forms Part 1 - RailsCasts](http://railscasts.com/episodes/73-complex-forms-part-1)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.
