Topic: Webpage for game (cups, ladders), uml

Hi.

Im making webpage for one game community. (Im newbie, so don't hit face:))
Cups, ladders included.

First time i tried to make some kind of diagram to understand what im doing:
Here is part of diagram models:
http://urgas.eu/stuff/diagram.png (picture)
http://urgas.eu/stuff/diagram.dia (DIA (Gnome diagram editor)

Im already confused of clan part. Clan has one clan_admin and one match_arranger. I should make tabel for each or I just make columns for clan table? Second variant i think.

I see mistakes in that diagram, but i just don't know how to fix them.


Maybe someone can give me good hints.

Re: Webpage for game (cups, ladders), uml

innu wrote:

Im already confused of clan part. Clan has one clan_admin and one match_arranger. I should make tabel for each or I just make columns for clan table? Second variant i think.

What is the relation between clan and member? Does each clan have many members? Is one member of each clan considered an admin, and another member a match arranger? Can they both be the same member? Does the admin and match arranger have their own attributes?

innu wrote:

I see mistakes in that diagram, but i just don't know how to fix them.

Can you go into detail on the problems? I'm not familiar with the game so it's hard to say what is wrong and how to improve it.

Railscasts - Free Ruby on Rails Screencasts

Re: Webpage for game (cups, ladders), uml

ryanb wrote:

What is the relation between clan and member? Does each clan have many members? Is one member of each clan considered an admin, and another member a match arranger? Can they both be the same member? Does the admin and match arranger have their own attributes?

Members>Member_type>
Here is Admin, SubAdmin, Member.

Clan have many members (member_type dosen't count in here).
Clan has one clan admin. Clan admin can edit clan settings, arrange matches, invite members(without clan) and promote clan one member to match arranger.
Clan match arranger can arrane_matches.
It's not necessary that clan has match arranger.

Clan admin and match_arranger dosen't have their own attributes.


I got some ideas, when posting this post tongue. Already helped a bit.
I'll try to develop a bit. Then I'll probably can ask a bit better questions.

Re: Webpage for game (cups, ladders), uml

If an admin or match arranger doesn't need its own attributes, it's not necessary to place it in its own table. So you can add admin_id and match_arranger_id columns in the clans table and do this:

class Clan < ActiveRecord::Base
  has_many :members
  belongs_to :admin, :class_name => 'Member', :foreign_key => 'admin_id'
  belongs_to :match_arranger, :class_name => 'Member', :foreign_key => 'match_arranger_id'
end

An alternative (and probably better) approach is to use Single Table Inheritance. By adding a type column to the members table, you can subclass Member with Admin and MatchAssigner. You can then easily give each class its own behavior and permissions. This will only work well if a given member cannot be both Admin and MatchAssigner and cannot belong to multiple clans.

Last edited by ryanb (2006-12-21 14:50:43)

Railscasts - Free Ruby on Rails Screencasts

Re: Webpage for game (cups, ladders), uml

class LadderController < ApplicationController

  before_filter :login_required, :except => [:show, :list]

  ## Join / leave method: only clan_admins clan use it.
  ## how should i make filter. Just add check methods to application? and use somthing like this:
  ## before_filter :clan_admin_required, :only => [:join, :leave]

  ## Right now it's like this: (maybe some mistakes, haven't tested it yet)
  def join
    @ladder = Ladder.find(params[:id])
    @clan = current_member.clan
    unless current_member.clan_admin?
      flash[:error] = "You are not admin of \"#{@clan.name}\" clan"
      redirect_to :action => 'show', :id => @ladder
    end
    unless @clan.ladder(@ladder).nil?
      flash[:error] = "This clan is already joined to \"#{@ladder.name}\" ladder"
      redirect_to :action => 'show', :id => @ladder
    end
    @clanladder = ClansLadder.new
    @clanladder.ladder = @ladder
    @clanladder.clan = @clan
    if @clanladder.save
      flash[:notice] = "Successfully joined ladder"
      redirect_to :action => 'show', :id => @ladder
    end
  end

Last edited by innu (2006-12-22 09:30:17)

Re: Webpage for game (cups, ladders), uml

Got one problem more:

## ladder.rb
  has_many :ladder_admins, :foreign_key => 'ladder_id', :dependent => :destroy
  has_many :admins, :through => :ladder_admins

## ladder_admin.rb
  belongs_to :ladder
  belongs_to :member

## member.rb
  has_many :ladder_admins, :foreign_key => 'member_id', :dependent => :destroy
  has_many :ladders, :through => :ladder_admins


ladder_admins sql:
ladder_id, member_id

has_many :admins, :through => :ladder_admins << dont work because there is no admin_id field. right? With has_many :members it works. If I try to use class_name, foreign_key options, I just get:
ActiveRecord::HasManyThroughSourceAssociationNotFoundError: ActiveRecord::HasManyThroughSourceAssociationNotFoundError

Re: Webpage for game (cups, ladders), uml

innu wrote:

has_many :admins, :through => :ladder_admins << dont work because there is no admin_id field. right? With has_many :members it works. If I try to use class_name, foreign_key options, I just get:
ActiveRecord::HasManyThroughSourceAssociationNotFoundError: ActiveRecord::HasManyThroughSourceAssociationNotFoundError

I think you need to use the :source option of has_many :through

has_many :admins, :through => :ladder_admins, :source => :member

Railscasts - Free Ruby on Rails Screencasts

Re: Webpage for game (cups, ladders), uml

Thanks, it worked.

Need some help again.

I have models.
Example: ladder.rb
I want methods:
member_can_see
member_can_edit
etc.

But in models, i can't use current_user.

def member_can_see
  true if current_member.is_admin?
  true if ladder_admin?
end

def ladder_admin?
  true if self.admins.include?(current_member)
end


In cup model, theres similar methods.

How should i build this kind of user system?

Use def member_can_see(member) ?

Last edited by innu (2006-12-25 14:04:38)

Re: Webpage for game (cups, ladders), uml

innu wrote:

Use def member_can_see(member) ?

Yep, either do that or put the permissions into the user model as I have done.

Railscasts - Free Ruby on Rails Screencasts