Module: LookupCommon
- Extended by:
- ActiveSupport::Concern
- Included in:
- Logistics::Core::AcquisitionModesController, Logistics::Core::CargoTypesController, Logistics::Core::ChargeableServiceTypesController, Logistics::Core::ClientCategoriesController, Logistics::Core::CommunicationChannelsController, Logistics::Core::ContainerArrangementsController, Logistics::Core::CountriesController, Logistics::Core::CurrenciesController, Logistics::Core::CustomsOfficeUnitsController, Logistics::Core::DeliveryTermsController, Logistics::Core::EntryPointsController, Logistics::Core::OperationTypesController, Logistics::Core::PaymentTermsController, Logistics::Core::ServiceDeliveryUnitTypesController, Logistics::Core::TransactionTypesController, Logistics::Core::TransportModalitiesController, Logistics::Core::TransportModesController, Logistics::Core::TransportServiceTypesController, Logistics::Core::UnitOfChargesController
- Defined in:
- app/controllers/concerns/lookup_common.rb
Instance Method Summary collapse
- #create ⇒ Object
- #get_model(type = nil) ⇒ Object
- #get_model_name ⇒ Object
- #index ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/concerns/lookup_common.rb', line 17 def create clazz = get_model obj = clazz.new(lookup_params) class_name = get_model_name.split('::').last.underscore.humanize if obj.save response = Mks::Common::MethodResponse.new(true, "#{class_name} saved successfully!",obj, nil, nil) else errors = Mks::Common::Util. obj, class_name response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) end render json: response end |
#get_model(type = nil) ⇒ Object
41 42 43 44 45 46 |
# File 'app/controllers/concerns/lookup_common.rb', line 41 def get_model(type = nil) if type return type.constantize end get_model_name.constantize end |
#get_model_name ⇒ Object
48 49 50 51 52 |
# File 'app/controllers/concerns/lookup_common.rb', line 48 def get_model_name name = self.class.to_s name.slice!('Controller') name.singularize end |
#index ⇒ Object
10 11 12 13 14 15 |
# File 'app/controllers/concerns/lookup_common.rb', line 10 def index p = params[:type] clazz = get_model(p) response = Mks::Common::MethodResponse.new(true, nil, clazz.all, nil, nil) render json: response end |
#update ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'app/controllers/concerns/lookup_common.rb', line 30 def update class_name = get_model_name.split('::').last.underscore.humanize if @lookup.update(lookup_params) response = Mks::Common::MethodResponse.new(true, "#{class_name} updated successfully!", @lookup, nil, nil) else errors = Mks::Common::Util. @lookup, class_name response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) end render json: response end |