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 return_to = params[:editable_content][:redirect_to].presence if @editable_content.update(content_params) if return_to redirect_to return_to else render status: :ok end 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