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
Maybe you could just stick with a User and Events model. Then each
has_and_belongs_to_many :events/:users.
-Ryan
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.
BTW, YAML form builder:
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.
thanks,
that railscastis realy helpfull