레일 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) 전체 경로가 필요합니다. 누구든지 내 파일의 전체 경로를 지정하는 방법을 알고 있습니까?
파일을 업로드하는 방법은 무엇입니까? 양식 및 반송파 코드를 게시 할 수 있습니까? – Mandeep
@Mandeep <% = cloudy_js_config %>
너클을 만듭니다.
<% = form_for : 너트, url : 너트 경로 | f | %> <% = cl_image_upload_tag (: image_id) %> <% = f.submit! "너트 그것을"%> <% end %> –SOS하시기 바랍니다 @Mandeep –