Module: TenaDcms::Common
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/controllers/concerns/tena_dcms/common.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/concerns/tena_dcms/common.rb', line 25 def create obj = if block_given? yield else @clazz.new(model_params) end if obj.save render json: { success: true, data: serialize(obj) }, status: :created else render json: { success: false, error: obj.errors.[0] }, status: :unprocessable_entity end rescue StandardError => e render json: { success: false, error: e. } end |
#destroy ⇒ Object
55 56 57 |
# File 'app/controllers/concerns/tena_dcms/common.rb', line 55 def destroy @obj.destroy end |
#index ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'app/controllers/concerns/tena_dcms/common.rb', line 12 def index data = if block_given? yield else @clazz.all end render json: { success: true, data: serialize(data) } end |
#show ⇒ Object
21 22 23 |
# File 'app/controllers/concerns/tena_dcms/common.rb', line 21 def show render json: { success: true, data: serialize(@obj) } end |
#update ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/controllers/concerns/tena_dcms/common.rb', line 40 def update if block_given? yield else obj = @obj end if obj.update(model_params) render json: { success: true, data: serialize(obj) }, status: :ok else render json: { error: obj.errors, success: false }, status: :unprocessable_entity end rescue StandardError => e render json: { success: false, error: e. } end |