Files
fetsite/app/models/modul.rb
Andreas Stephanides c3e1a23073 bulk modul edit
2014-04-04 14:13:47 +02:00

45 lines
1.2 KiB
Ruby
Executable File

# -*- coding: utf-8 -*-
# == Schema Information
#
# Table name: moduls
#
# id :integer not null, primary key
# name :string(255)
# desc :text
# depend :text
# created_at :datetime not null
# updated_at :datetime not null
#
class Modul < ActiveRecord::Base
attr_accessible :desc,:name, :depend, :studium_id, :modulgruppen
has_and_belongs_to_many :lvas , :uniq=>true
has_and_belongs_to_many :modulgruppen
validates :modulgruppen, :presence=>true # Ein Modul muss zu einer Modulgruppe gehören
validates :name, :presence=>true # Ein Modul muss einen Namen haben
translates :desc,:depend,:name, :versioning =>true, :fallbacks_for_empty_translations => true
def self.update_multiple(hash)
m= []
hash.each_entry do |h|
if h["id"].to_i == 0
unless h["name"].empty?
md=Modul.new(:name=>h["name"],:desc=>h["desc"],:depend=>h["depend"])
md.modulgruppen=Modulgruppe.where(:id => h["modulgruppe_ids"].map(&:to_i))
md.save
m << md
end
else
md=Modul.find(h["id"].to_i)
md.name=h["name"]
md.modulgruppen=Modulgruppe.where(:id => h["modulgruppe_ids"].map(&:to_i))
m << md
end
end
m
end
end