Module: ParentControl

Extended by:
ActiveSupport::Concern
Included in:
AbstractResourcesController
Defined in:
app/controllers/concerns/parent_control.rb

Instance Method Summary collapse



39
40
41
42
43
44
45
# File 'app/controllers/concerns/parent_control.rb', line 39

def set_parents
  @parents = []
  return @parents unless resource_class.respond_to? :roots #( 'arraying') && resource? )
  @parents = resource_class.arraying({ order: 'name'}, resource.possible_parents)
rescue Exception => e
  scoop_from_error e
end

#update_parenthood ⇒ Object

/employees/1/teams/new

/employees/1/teams/1/edit

/employees/1/teams/1/delete



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/controllers/concerns/parent_control.rb', line 104

def update_parenthood
  if params[:parent] and params[:parent_id]
    # raise "Ups - is this ready for prime time yet?"
    parent = params[:parent].classify.constantize.find(params[:parent_id])
    unless parent.blank?
      case params[:action]
      when "create"
        children = eval("parent.#{resource_name}")
        children << resource unless children.include? resource
      # when "edit"
      when "delete"
        children = eval("parent.#{resource_name}")
        children >> resource
      end
    end
  end
  true
rescue
  false
end