Add admin/editable_contents controller

This commit is contained in:
Râu Cao 2025-05-28 18:40:54 +04:00
parent 55c63be9e2
commit 2f86b3c16f
Signed by: raucao
GPG Key ID: 37036C356E56CC51
2 changed files with 41 additions and 4 deletions

View File

@ -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

View File

@ -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