Class: Eventable::Categorylist
- Inherits:
-
Object
- Object
- Eventable::Categorylist
- Defined in:
- app/models/eventable/categorylist.rb
Defined Under Namespace
Classes: CategoryItem
Instance Attribute Summary collapse
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
Instance Method Summary collapse
- #errors ⇒ Object
-
#initialize(event) ⇒ Categorylist
constructor
A new instance of Categorylist.
- #items_attributes=(attr) ⇒ Object
- #save ⇒ Object
- #update_attributes(attrs) ⇒ Object
Constructor Details
#initialize(event) ⇒ Categorylist
Returns a new instance of Categorylist.
23 24 25 26 |
# File 'app/models/eventable/categorylist.rb', line 23 def initialize(event) @event = event @items = Eventable::Category.all.map { |c| CategoryItem.new(event, c)} end |
Instance Attribute Details
#event ⇒ Object (readonly)
Returns the value of attribute event.
3 4 5 |
# File 'app/models/eventable/categorylist.rb', line 3 def event @event end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
3 4 5 |
# File 'app/models/eventable/categorylist.rb', line 3 def items @items end |
Instance Method Details
#errors ⇒ Object
28 29 30 |
# File 'app/models/eventable/categorylist.rb', line 28 def errors ActiveRecord::Errors.new(self) end |
#items_attributes=(attr) ⇒ Object
32 33 34 35 36 |
# File 'app/models/eventable/categorylist.rb', line 32 def items_attributes=(attr) attr.values.each do |a| @items.detect { |i| i.id == a[:id].to_i }.active = (a[:active] == '1') end end |
#save ⇒ Object
45 46 47 |
# File 'app/models/eventable/categorylist.rb', line 45 def save @event.category_ids = @items.select(&:active).map(&:id) end |
#update_attributes(attrs) ⇒ Object
38 39 40 41 42 43 |
# File 'app/models/eventable/categorylist.rb', line 38 def update_attributes(attrs) attrs.each do |k,v| send "#{k}=", v end save end |