Hala çok yeni raylar için yeni; bu dosya S3'e ilk defa dosya yüklüyorum. Uygulamamda carrierwave gemini kullandım ve bir dosya seçip kaydedebiliyorum. Carrierwave ile S3 arasındaki bağlantı çalışıyor gibi görünüyor çünkü resimler S3 grubumda görünüyor. Sorun şu ki resmimdeki resmi göremiyorum ve bunun nedenini anlayamıyorum.Görüntüleri S3'e yüklüyor ama onları uygulamamda göremiyorum
class ProductsController < ApplicationController
before_action :set_product, only: [:show, :edit, :update, :destroy]
# GET /products
# GET /products.json
def index
@products = Product.all
@uploader = Product.new.image
@uploader.success_action_redirect = new_product_path
end
# GET /products/1
# GET /products/1.json
def show
end
# GET /products/new
def new
@product = Product.new(key: params[:key])
end
# GET /products/1/edit
def edit
end
# POST /products
# POST /products.json
def create
@product = Product.new(product_params)
respond_to do |format|
if @product.save
format.html { redirect_to @product, notice: 'Product was successfully created.' }
format.json { render :show, status: :created, location: @product }
else
format.html { render :new }
format.json { render json: @product.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /products/1
# PATCH/PUT /products/1.json
def update
respond_to do |format|
if @product.update(product_params)
format.html { redirect_to @product, notice: 'Product was successfully updated.' }
format.json { render :show, status: :ok, location: @product }
else
format.html { render :edit }
format.json { render json: @product.errors, status: :unprocessable_entity }
end
end
end
# DELETE /products/1
# DELETE /products/1.json
def destroy
@product.destroy
respond_to do |format|
format.html { redirect_to products_url, notice: 'Product was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_product
@product = Product.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def product_params
params.require(:product).permit(:title, :description, :image, :price, :category, :subcategory)
end
end
ImageUploder:
# encoding: utf-8
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWaveDirect::Uploader
include CarrierWave::RMagick
include CarrierWave::MimeTypes
process :set_content_type
version :thumb do
process resize_to_fill: [200,200]
end
end
show.html.erb (görüntü gösterilmesini olmalıdır):
<p id="notice"><%= notice %></p>
<p>
<strong>Title:</strong>
<%= @product.title %>
</p>
<p>
<strong>Description:</strong>
<%= @product.description %>
</p>
<p>
<strong>Image:</strong>
<%= @product.image_url %>
</p>
<p>
<strong>Price:</strong>
<%= @product.price %>
</p>
<p>
<strong>Category:</strong>
<%= @product.category %>
</p>
<p>
<strong>Subcategory:</strong>
<%= @product.subcategory %>
</p>
<%= link_to 'Edit', edit_product_path(@product) %> |
<%= link_to 'Back', products_path %>
product.rb İşte
benim denetleyicisi olan :class Product < ActiveRecord::Base
attr_accessor :image
mount_uploader :image, ImageUploader
after_save :enqueue_image
def image_name
File.basename(image.path || image.filename) if image
end
def enqueue_image
ImageWorker.perform_async(id,key) if key.presemt?
end
class ImageWorker
include Sidekiq::Worker
def perform(id, key)
product = Product.find(id)
product.key = key
product.remote_image_url = product.image.direct_fog_url(with_path: true)
end
end
end
Yardımlarınız için şimdiden teşekkür ederiz!
değişen? ' – archana