themes image fix

This commit is contained in:
呱呱呱 2023-08-24 16:03:40 +08:00
parent 3dacc83e4a
commit 31bb2502b8
5 changed files with 25 additions and 10 deletions

View File

@ -18,7 +18,7 @@ class Admins::PageThemesController < Admins::BaseController
end end
def create def create
@page_theme = PageTheme.new update_params @page_theme = PageTheme.new theme_params
if @page_theme.save if @page_theme.save
save_image_file(params[:image]) save_image_file(params[:image])
redirect_to admins_page_themes_path redirect_to admins_page_themes_path
@ -44,9 +44,15 @@ class Admins::PageThemesController < Admins::BaseController
end end
def update def update
@page_theme.update(update_params) @page_theme.attributes = theme_params
flash[:success] = '保存成功' if @page_theme.save
render 'edit' save_image_file(params[:image])
redirect_to admins_page_themes_path
flash[:success] = "更新成功"
else
redirect_to admins_page_themes_path
flash[:danger] = "更新失败"
end
end end
private private
@ -54,7 +60,7 @@ class Admins::PageThemesController < Admins::BaseController
@page_theme = PageTheme.find(params[:id]) @page_theme = PageTheme.find(params[:id])
end end
def update_params def theme_params
params.require(:page_theme).permit(:language_frame, :name, :cate, :image_url, :clone_url) params.require(:page_theme).permit(:language_frame, :name, :cate, :image_url, :clone_url)
end end

View File

@ -56,8 +56,7 @@ class SitePagesController < ApplicationController
def themes def themes
# data = YAML.load_file(Rails.root.join('config/admins', 'page_themes.yml')) # data = YAML.load_file(Rails.root.join('config/admins', 'page_themes.yml'))
# render_ok({themes:data[theme_params.downcase]}) # render_ok({themes:data[theme_params.downcase]})
data = PageTheme.where(language_frame:theme_params).order(order_index: :asc) @themes = PageTheme.where(language_frame:theme_params).order(order_index: :asc)
render_ok ({themes:data})
end end
private private

View File

@ -18,11 +18,11 @@ class PageTheme < ApplicationRecord
def image def image
image_url('image') page_image_url('image')
end end
private private
def image_url(type) def page_image_url(type)
return nil unless Util::FileManage.exists?(self, type) return nil unless Util::FileManage.exists?(self, type)
Util::FileManage.source_disk_file_url(self, type) Util::FileManage.source_disk_file_url(self, type)
end end

View File

@ -7,7 +7,7 @@
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
</button> </button>
</div> </div>
<%= simple_form_for(@page_theme, url: admins_page_themes_path(@page_theme)) do |p| %> <%= form_for @page_theme, url: {controller: "page_themes", action: "#{type}"}, html: { enctype: 'multipart/form-data' } do |p| %>
<div class="modal-body"> <div class="modal-body">
<div class="form-group"> <div class="form-group">
<label> <label>

View File

@ -0,0 +1,10 @@
json.total_count @themes.size
json.themes @themes.map{|e|
{
name: e.name,
language_frame: e.language_frame,
image: e.image,
clone_url: e.clone_url,
order_index: e.order_index,
}
}