select image for section logic

This commit is contained in:
Torsten 2022-11-28 00:39:24 +02:00
parent 76b29123a6
commit 38caa2ea9a
4 changed files with 32 additions and 4 deletions

View File

@ -1,6 +1,10 @@
module Cms
class SectionsController < CmsController
before_action :set_page, only: %i[ show edit update destroy ]
before_action :set_page, only: %i[ show edit update destroy set_image select_image]
def select_image
@images = Image.all
end
def update
@section.content.each do |key , value|
@ -17,7 +21,8 @@ module Cms
private
def set_page
@page = Page.find(params[:page_id])
@section = @page.find_section( params[:id] )
section_id = params[:id] || params[:section_id]
@section = @page.find_section( section_id )
end
end

View File

@ -1,7 +1,7 @@
.relative.block.border.border-gray-100
%h3.mt-4.text-lg.font-bold= key.upcase
%button.ml-3.inline-block.rounded-lg.bg-blue-500.px-5.py-3.text-sm.font-medium.text-white
Update
=link_to "Update Image" , cms_page_section_select_image_url(@page.name,@section.id)
.relative.block.border.border-gray-100
-if value

View File

@ -0,0 +1,20 @@
.grid.grid-cols-6.gap-4.m-8
-@images.each do |name , image|
.relative.block.border.border-gray-100
=image_tag("cms/#{name}" , class: "h-56 w-full object-contain lg:h-72")
.p-6
%strong.inline-block.bg-yellow-400.px-3.py-1.text-xs.font-medium
=image.type
%h3.mt-4.text-lg.font-bold= image.name
%p.mt-2.text-sm.text-gray-700 $14.99
%button.mt-4.block.w-full.rounded-sm.bg-yellow-500.p-4.text-sm.font-medium{:type => "button"}
Add to Cart
.relative.block.border.border-gray-100
.p-6
%h3.mt-4.text-lg.font-bold Add new Image
= form_tag(cms_images_path, method: :post , multipart: true) do
= text_field_tag 'filename'
= file_field_tag 'image_file'
= hidden_field_tag :redirect , "someURL"
= submit_tag 'Submit'

View File

@ -2,7 +2,10 @@ Rails.application.routes.draw do
namespace :cms do
resources :pages do
resources :sections
resources :sections do
get :select_image
get :set_image
end
end
resources :images
end