I need help building a relationship model.

15 views
Skip to first unread message

David Williams

unread,
Jan 12, 2015, 4:40:43 PM1/12/15
to rubyonra...@googlegroups.com
I created a scaffold that has a controller and model for an activism
events feature where individual activism networks will post events for
their supporters to attend. Called EventsController and :events model

The events table has a laundry list of properties for the create method.
Right now, I'm trying to figure out how to give users outside of the
events creator the ability to sign up to attend those events.
How would you develop such a relationship between a show post and a
sign-up form for normal users?

Right now,
my Event.rb
has belongs_to :activism_co_user
has_one :category

Activism_co_user.rb
has_many :events

The table itself has quite a few properties that describe what the event
will be and how many people can attend. What I would I like to is allow
them to limit the amount of tickets for an event, and let users pick
options like donate to their charity using a stripe mechanism during
checkout

--
Posted via http://www.ruby-forum.com/.

Colin Law

unread,
Jan 12, 2015, 5:05:36 PM1/12/15
to rubyonra...@googlegroups.com
On 12 January 2015 at 21:40, David Williams <li...@ruby-forum.com> wrote:
> I created a scaffold that has a controller and model for an activism
> events feature where individual activism networks will post events for
> their supporters to attend. Called EventsController and :events model
>
> The events table has a laundry list of properties for the create method.
> Right now, I'm trying to figure out how to give users outside of the
> events creator the ability to sign up to attend those events.
> How would you develop such a relationship between a show post and a
> sign-up form for normal users?
>
> Right now,
> my Event.rb
> has belongs_to :activism_co_user

What??

> has_one :category
>
> Activism_co_user.rb
> has_many :events
>
> The table itself has quite a few properties that describe what the event
> will be and how many people can attend. What I would I like to is allow
> them to limit the amount of tickets for an event, and let users pick
> options like donate to their charity using a stripe mechanism during
> checkout

If I understand correctly then possibly you will want a join model
called something like attendance where
user has_many attendances
user has_many events through attendances

event has_many attendances
event has_many users through attendances

attendance belongs to event and belongs to user.

What on earth is an activism_co_user?

Colin

David Williams

unread,
Jan 12, 2015, 8:22:42 PM1/12/15
to rubyonra...@googlegroups.com
Colin Law wrote in post #1166568:
I apologize, that would be the name of the second user model. From what
you're telling me. I need another model named attendances. What might
the contents of that model pertain? I'll refractor the name of the
second user model before going into production. (I won't let normal
users create their own events btw.) The create action will only be
available on the company's side to avoid criminal activities.

David Williams

unread,
Jan 12, 2015, 10:21:49 PM1/12/15
to rubyonra...@googlegroups.com
Colin Law wrote in post #1166568:
> If I understand correctly then possibly you will want a join model
> called something like attendance where
> user has_many attendances
> user has_many events through attendances
>
> event has_many attendances
> event has_many users through attendances
>
> attendance belongs to event and belongs to user.
>
> What on earth is an activism_co_user?
>
> Colin

As in does it need some form of id within the attendance model - I'll
have to create a separate table for it. I just need the traditional db
properties that you might use in this instance.

:attendances

Colin Law

unread,
Jan 13, 2015, 4:36:06 AM1/13/15
to rubyonra...@googlegroups.com
It is almost always a bad idea to have have separate tables for
different user types. Just use an authorisation gem such as pundit to
allow different users to have different capabilities.

That you have to ask the question about how join models work suggests
you are a beginner at rails. Before going further I suggest you work
right through a good tutorial such as railstutorial.org (which is free
to use online) so that you understand the basics of rails.

Also have a look at the Rails Guides.

Colin
Reply all
Reply to author
Forward
0 new messages