mardi 21 février 2017

create a wrapper controller for all calls to web services in rails

I am working to creating a wrapper for my existing application controllers.

For example, i have two controllers accepting similar set of parameters and similar methods.

Code is as below

class EmployeeController < ApplicationController

  def list
  end

end


class DepartmentController < ApplicationController

  def list
  end

end

end point would be http://localhost:3000/employee/list & http://localhost:3000/department/list

What is the best way to create wrapper controller and invoke either of the controllers action.

is this way correct, where we check certain parameters and create objects accordingly or are there better ways to do it

class WrapperController < ApplicationController


  def list
    if params["which"].eql?("employee")
      data = EmployeeController.new(params).create
    else
      data = DepartmentController.new(params).label
    end

  end
end

end point would be http://localhost:3000/wrapper/list

Any help would be appreciated. Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire