1

레일 3을 사용하여 구름과 캐리어 웨이브로 서버에 사진을 업로드하고 있습니다.구름이있는 웹 사이트에 사진 업로드 - 절대 경로가 필요합니다.

class NutsController < ApplicationController 
    include UsersHelper 
    include NutsHelper 

    def index 
    if current_user 
     @user = User.find(session[:user_id]) 
     @nuts = Nut.all 
    else 
     redirect_to :root 
    end 
    end 

    def new 
    # current_user 
    end 

    def show 
    end 

    def create 
    if params[:file].present? 
     @upload = Cloudinary::Uploader.upload(params[:file]) 
     @picture = @upload["secure_url"] 
    end 

    @nut = Nut.new(url: [@picture]) 
    if @nut.save 
     redirect_to user_path(current_user) 
    end 
    end 
end 

< ------------------------------------------ >

<%= cloudinary_js_config %> 
<h1>Create a Nushell</h1> 
<%= form_for :nut, url: nuts_path do |f| %> 

    <%= cl_image_upload_tag(:image_id) %> 

    <%= f.submit "Nut it Up!"%> 
<% end %> 

class PictureUploader < CarrierWave::Uploader::Base 
    include Cloudinary::CarrierWave 

    storage :file 

    def store_dir 
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" 
    end 
end 

내 파일 Yellow_Happy.jpg 지정됩니다. params [: file]를 출력하면 'Yellow_Happy.jpg'를 반환합니다. 클라우드에 업로드하려면 내 파일 (예 : Users/apprentice/Desktop/Yellow_Happy.jpg) 전체 경로가 필요합니다. 누구든지 내 파일의 전체 경로를 지정하는 방법을 알고 있습니까?

+0

파일을 업로드하는 방법은 무엇입니까? 양식 및 반송파 코드를 게시 할 수 있습니까? – Mandeep

+0

@Mandeep <% = cloudy_js_config %>

너클을 만듭니다.

<% = form_for : 너트, url : 너트 경로 | f | %> <% = cl_image_upload_tag ​​(: image_id) %> <% = f.submit! "너트 그것을"%> <% end %> –

+0

SOS하시기 바랍니다 @Mandeep –

답변

1

당신이 당신의 업 로더 코드를 보면 당신은 기본적으로 및 여기서 store_dir 기능은 이미지을 업로드 할 위치를 알려주는 응용 프로그램 내에서 이미지를 업로드 carrierwave을 알려줍니다 storage :file을 지정했습니다. 에서 확인할 수도 있습니다. 당신이 cloudinary documentation 보면 자세한 내용이 carrierwave documentation

체크 아웃의 경우 만 (섬네일 또는 다른 carrierwave 기능을 사용하지 않는 경우) 이 업 로더에 Cloudinary :: CarrierWave을 포함해야합니다. 업 로더는 다음과 같아야합니다.

class PictureUploader < CarrierWave::Uploader::Base 
    include Cloudinary::CarrierWave 

    #storage :file #You don't need it 

    def store_dir 
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" 
    end 
end 
관련 문제