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

View File

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

View File

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

View File

@ -7,7 +7,7 @@
<span aria-hidden="true">&times;</span>
</button>
</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="form-group">
<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,
}
}