fix für bulk edit moduls

This commit is contained in:
Andreas Stephanides
2014-04-04 14:50:48 +02:00
parent c3e1a23073
commit 87cad4b910
4 changed files with 21 additions and 5 deletions

View File

@@ -23,8 +23,9 @@ class Modul < ActiveRecord::Base
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
if hash.is_a? Hash
hash.each do |i,h|
if i.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))
@@ -37,8 +38,17 @@ class Modul < ActiveRecord::Base
md.modulgruppen=Modulgruppe.where(:id => h["modulgruppe_ids"].map(&:to_i))
m << md
end
end
else
hash.each do |h|
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
end
end
m
end
end

View File

@@ -29,6 +29,7 @@
class Studium < ActiveRecord::Base
attr_accessible :desc, :name,:abkuerzung, :typ, :zahl, :semester, :picture, :picture_cache, :qualifikation,:struktur, :jobmoeglichkeiten
has_many :modulgruppen, inverse_of: :studium, :class_name => "Modulgruppe", :dependent => :destroy
has_many :semester, :dependent => :destroy
validates :abkuerzung, :length=>{:maximum=>5}, :format=>{:with=>/^[a-zA-z]{0,5}$/}
validates :typ, :inclusion => {:in => ["Bachelor","Master"] }