first upload working (wip)
This commit is contained in:
parent
43a759cec4
commit
b853a1201b
@ -3,12 +3,26 @@ module Cms
|
|||||||
class ImageController < ApplicationController
|
class ImageController < ApplicationController
|
||||||
|
|
||||||
@@root = "app/assets/images/cms/"
|
@@root = "app/assets/images/cms/"
|
||||||
@@files = Dir.new(Rails.root + @@root).children
|
@@files = Set.new Dir.new(Rails.root + @@root).children
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@files = files
|
@files = files
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
io = params['image_file']
|
||||||
|
ending = io.original_filename.split("/").last.split(".").last
|
||||||
|
filename = params['filename'] + "." + ending
|
||||||
|
File.open(Rails.root.join('app/assets/images/cms', filename), "wb") do |f|
|
||||||
|
f.write io.read
|
||||||
|
end
|
||||||
|
@@files << filename
|
||||||
|
redirect_to cms_image_index_path
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def files
|
def files
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
%section
|
||||||
|
%a.inline-block.rounded.border.border-indigo-600.bg-indigo-600.px-12.py-3.text-sm.font-medium.text-white.hover:bg-transparent.hover:text-indigo-600.focus:outline-none.focus:ring.active:text-indigo-500{:href => new_cms_image_path}
|
||||||
|
Add Image
|
||||||
|
|
||||||
.grid.grid-cols-6.gap-4.m-8
|
.grid.grid-cols-6.gap-4.m-8
|
||||||
-@files.each do |file|
|
-@files.each do |file|
|
||||||
.relative.block.border.border-gray-100
|
.relative.block.border.border-gray-100
|
||||||
@ -9,7 +13,7 @@
|
|||||||
.p-6
|
.p-6
|
||||||
%strong.inline-block.bg-yellow-400.px-3.py-1.text-xs.font-medium
|
%strong.inline-block.bg-yellow-400.px-3.py-1.text-xs.font-medium
|
||||||
New
|
New
|
||||||
%h3.mt-4.text-lg.font-bold= file
|
%h3.mt-4.text-lg.font-bold= file.split(".").first
|
||||||
%p.mt-2.text-sm.text-gray-700 $14.99
|
%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"}
|
%button.mt-4.block.w-full.rounded-sm.bg-yellow-500.p-4.text-sm.font-medium{:type => "button"}
|
||||||
Add to Cart
|
Add to Cart
|
||||||
|
4
app/views/cms/image/new.haml
Normal file
4
app/views/cms/image/new.haml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
= form_tag({action: :create}, multipart: true) do
|
||||||
|
= text_field_tag 'filename'
|
||||||
|
= file_field_tag 'image_file'
|
||||||
|
= submit_tag 'Submit'
|
15
spec/helpers/image_helper_spec.rb
Normal file
15
spec/helpers/image_helper_spec.rb
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
# Specs in this file have access to a helper object that includes
|
||||||
|
# the ImageHelper. For example:
|
||||||
|
#
|
||||||
|
# describe ImageHelper do
|
||||||
|
# describe "string concat" do
|
||||||
|
# it "concats two strings with spaces" do
|
||||||
|
# expect(helper.concat_strings("this","that")).to eq("this that")
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
RSpec.describe ImageHelper, type: :helper do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
7
spec/requests/image_spec.rb
Normal file
7
spec/requests/image_spec.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe "Images", type: :request do
|
||||||
|
describe "GET /index" do
|
||||||
|
pending "add some examples (or delete) #{__FILE__}"
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user