Module: GetsKlass

Extended by:
ActiveSupport::Concern
Included in:
RestArea::MessageController, RestArea::RestController
Defined in:
app/controllers/concerns/gets_klass.rb

Instance Method Summary collapse

Instance Method Details

#get_klassObject



8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/concerns/gets_klass.rb', line 8

def get_klass
  rescue_uninitialized_constant do
    klass = params[:klass].classify.constantize
    @resource = RestArea.resources[klass.name.underscore.to_sym]
    @klass = @resource.klass
  end
  test_class(@klass)

  @roots = ActionController::Base.helpers.sanitize(params[:klass]).pluralize
  @root = @roots.singularize
end

#test_class(klass) ⇒ Object



20
21
22
23
24
# File 'app/controllers/concerns/gets_klass.rb', line 20

def test_class(klass)
  if klass.nil? || !RestArea.resources.include?(klass.name.underscore.to_sym)
    raise ActionController::RoutingError.new("Resource Does Not Exist")
  end
end