Class: AsyncDataFetch::FetchersController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- AsyncDataFetch::FetchersController
- Defined in:
- app/controllers/async_data_fetch/fetchers_controller.rb
Overview
::ApplicationController
Instance Method Summary collapse
Instance Method Details
#get_async_data ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/async_data_fetch/fetchers_controller.rb', line 6 def get_async_data model = fetcher_params[:model_name].classify.constantize if model == nil then respond_to do |format| format.json { render :json => { :error => t( "async_data_fetch.Wrong_model")}, :status => 422 } end return end item = model.find_by(id: fetcher_params[:model_id]) if item == nil then respond_to do |format| format.json { render :json => { :error => t( "async_data_fetch.Wrong_id")}, :status => 422} end return end result = nil if item != nil && model.async_data_fetch_available_methods != nil && model.async_data_fetch_available_methods.include?(fetcher_params[:model_method]) then result = item.send(fetcher_params[:model_method]) respond_to do |format| format.json { render :json => { :success => result }, :status => 200 } end return end respond_to do |format| format.json { render :json => { :error => t( "async_data_fetch.Invalid_method") }, :status => 422 } end return end |