Class: MetaFieldApi::MetafieldsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- MetaFieldApi::MetafieldsController
- Defined in:
- app/controllers/meta_field_api/metafields_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
Store metafields.
- #destroy ⇒ Object
-
#index ⇒ Object
List of all metafields.
-
#show ⇒ Object
Show specific metafield.
-
#update ⇒ Object
Update specific metafield.
Instance Method Details
#create ⇒ Object
Store metafields
16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/controllers/meta_field_api/metafields_controller.rb', line 16 def create = Metafield.new() if .save render json: { metafield: , message: 'Metafield created successfully!' }, status: :created else render json: { error: .errors }, status: :unprocessable_entity end rescue StandardError => e render json: { error: e. }, status: :unprocessable_entity end |
#destroy ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'app/controllers/meta_field_api/metafields_controller.rb', line 52 def destroy = Metafield.find_by(id: params[:id]) if &.destroy render json: { message: 'Metafield deleted successfully!' }, status: :ok else render json: { error: 'Metafield not found or could not be deleted' }, status: :unprocessable_entity end end |
#index ⇒ Object
List of all metafields
4 5 6 7 8 9 10 11 12 13 |
# File 'app/controllers/meta_field_api/metafields_controller.rb', line 4 def index # Get the filter parameters from the params hash owner_type = params[:owner_type].presence owner_id = params[:owner_id].presence key = params[:key].presence namespace = params[:namespace].presence = Metafield.filter_by(owner_type, owner_id, key, namespace) render json: { metafields: , message: 'Metafields retrieved successfully!' }, status: :ok end |
#show ⇒ Object
Show specific metafield
29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/meta_field_api/metafields_controller.rb', line 29 def show = Metafield.find_by(id: params[:id]) if render json: { metafield: , message: 'Metafield retrieved successfully!' }, status: :ok else render json: { message: 'Metafield not found' }, status: :not_found end end |
#update ⇒ Object
Update specific metafield
40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/meta_field_api/metafields_controller.rb', line 40 def update = Metafield.find_by(id: params[:id]) if .update() render json: { metafield: , message: 'Metafield updated successfully!' }, status: :ok else render json: { error: .errors }, status: :unprocessable_entity end rescue StandardError => e render json: { error: e. } end |