Actually, some model names are in french so I translated, so it could
make more sens … but registration is inscription and groups are
periodes in the above example…
some code in the models are temporary, just so that I can debug more
easily.
Here are models and migrations
#########################################
class Inscription < ActiveRecord::Base
has_and_belongs_to_many :periodes
belongs_to :user
#restful_acl part - supposed to work fine###############
def is_updatable_by(user)
current_user.is_admin?
end
def is_deletable_by(user)
current_user.is_admin?
end
def self.is_readable_by(user, object = nil)
true
#current_user.is_admin?
end
def self.is_creatable_by(user)
current_user.is_admin?
#user != nil #Ensure the user is logged in
end
end
######################################
class Periode < ActiveRecord::Base
has_and_belongs_to_many :inscriptions
belongs_to :course
belongs_to :prof
def is_updatable_by(user)
current_user.is_admin?
end
def is_deletable_by(user)
current_user.is_admin?
end
def self.is_readable_by(user, object = nil)
true
#user != nil #Ensure the user is logged in
end
def self.is_creatable_by(user)
current_user.is_admin?
#user != nil #Ensure the user is logged in
end
end
other models
##########
user has_many :inscriptions
prof has_many :periodes
course has_many :periodes
##############################################
MIGRATIONS
#############################################
class CreatePeriodes < ActiveRecord::Migration
def self.up
create_table :periodes do |t|
t.integer :course_id
t.integer :prof_id
t.timestamps
end
end
def self.down
drop_table :periodes
end
end
#################
class CreateInscriptionsPeriodes < ActiveRecord::Migration
def self.up
create_table :inscriptions_periodes, :id => false do |t|
t.integer :inscription_id
t.integer :periode_id
t.timestamps
end
#add_index :inscriptions_periodes, [:inscription_id, :periode_id]
end
def self.down
drop_table :inscriptions_periodes
end
end
class CreateInscriptions < ActiveRecord::Migration
def self.up
create_table :inscriptions do |t|
t.integer :user_id
t.timestamps
end
end
def self.down
drop_table :inscriptions
end
end