select image for section logic
This commit is contained in:
parent
76b29123a6
commit
38caa2ea9a
@ -1,6 +1,10 @@
|
|||||||
module Cms
|
module Cms
|
||||||
class SectionsController < CmsController
|
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
|
def update
|
||||||
@section.content.each do |key , value|
|
@section.content.each do |key , value|
|
||||||
@ -17,7 +21,8 @@ module Cms
|
|||||||
private
|
private
|
||||||
def set_page
|
def set_page
|
||||||
@page = Page.find(params[:page_id])
|
@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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
.relative.block.border.border-gray-100
|
.relative.block.border.border-gray-100
|
||||||
%h3.mt-4.text-lg.font-bold= key.upcase
|
%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
|
%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
|
.relative.block.border.border-gray-100
|
||||||
-if value
|
-if value
|
||||||
|
20
app/views/cms/sections/select_image.haml
Normal file
20
app/views/cms/sections/select_image.haml
Normal 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'
|
@ -2,7 +2,10 @@ Rails.application.routes.draw do
|
|||||||
|
|
||||||
namespace :cms do
|
namespace :cms do
|
||||||
resources :pages do
|
resources :pages do
|
||||||
resources :sections
|
resources :sections do
|
||||||
|
get :select_image
|
||||||
|
get :set_image
|
||||||
|
end
|
||||||
end
|
end
|
||||||
resources :images
|
resources :images
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user