diff --git a/app/controllers/cms/sections_controller.rb b/app/controllers/cms/sections_controller.rb index b1668df..dd4eaab 100644 --- a/app/controllers/cms/sections_controller.rb +++ b/app/controllers/cms/sections_controller.rb @@ -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 diff --git a/app/views/cms/sections/editors/_image.haml b/app/views/cms/sections/editors/_image.haml index 7fab388..0e3b5c8 100644 --- a/app/views/cms/sections/editors/_image.haml +++ b/app/views/cms/sections/editors/_image.haml @@ -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 diff --git a/app/views/cms/sections/select_image.haml b/app/views/cms/sections/select_image.haml new file mode 100644 index 0000000..84c22ef --- /dev/null +++ b/app/views/cms/sections/select_image.haml @@ -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' diff --git a/config/routes.rb b/config/routes.rb index 83e7881..d42c8d9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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