From 2f86b3c16f2af407aae98968f2d86c1ac16f3cc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Wed, 28 May 2025 18:40:54 +0400 Subject: [PATCH] Add admin/editable_contents controller --- .../admin/editable_contents_controller.rb | 39 +++++++++++++++++++ config/routes.rb | 6 +-- 2 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 app/controllers/admin/editable_contents_controller.rb diff --git a/app/controllers/admin/editable_contents_controller.rb b/app/controllers/admin/editable_contents_controller.rb new file mode 100644 index 0000000..10140a0 --- /dev/null +++ b/app/controllers/admin/editable_contents_controller.rb @@ -0,0 +1,39 @@ +class Admin::EditableContentsController < Admin::BaseController + before_action :set_content, only: [:show, :edit, :update] + before_action :set_current_section, only: [:index, :show, :edit] + + def index + @path = params[:path].presence + scope = EditableContent.order(path: :asc) + scope = scope.where(path: @path) if @path + @pagy, @contents = pagy(scope) + end + + def show + end + + def edit + end + + def update + if @editable_content.update(content_params) + render json: { status: "success", message: "Content updated" }, status: :ok + else + render :edit, status: :unprocessable_entity + end + end + + private + + def set_content + @editable_content = EditableContent.find(params[:id]) + end + + def content_params + params.require(:editable_content).permit(:path, :key, :lang, :content, :rich_text) + end + + def set_current_section + @current_section = :content + end +end diff --git a/config/routes.rb b/config/routes.rb index 115fadd..094bf62 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -95,12 +95,10 @@ Rails.application.routes.draw do end end - # post 'users/:username/invitations', to: 'users#create_invitations' + resources :donations + resources :editable_contents, except: ['destroy'] get 'invitations', to: 'invitations#index' - - resources :donations - get 'lightning', to: 'lightning#index' namespace :app_catalog do