최근에 나는 이미지의 구름 저장소를 구름 레일 응용 프로그램의 carrierrwave와 통합 된 클라우드로 변경했습니다. 그것은 완벽하게 작동하지만 문제는 이미지를 업로드 한 후 사진이 비어 있다는 오류를 보여줍니다. 오류가 표시 되더라도 루트 URL을 수동으로 다시로드했습니다. 사진은 이미 업로드되었습니다. 문제는 새 게시물 및 편집 게시물에만 있지만 프로필 사진을 업데이트하고 프로필 사진을 추가해도 오류가 없습니다. simple_form
을 사용하여 사진을 업로드했습니다. 내가 무엇을 놓치고 있는지, 문제를 해결하도록 도와주세요. 사진을 업로드 한 후 This is the screenshot 개의 오류 페이지가 표시됩니다.carrierwave를 사용하여 스토리지를 cloudinary로 변경 한 후 레일 앱에 사진을 업로드 한 후 오류가 표시되는 이유는 무엇입니까?
나는 다음과 같은 단계를 따라했습니다 cloudinary 변경 동안 :
- 은 내가
photo_uploader.rb
에서cloudinary
을 포함storage :file
을 제거config/
디렉토리 - 에
cloudinary.yml
을 추가했다. - 마지막으로, 나는
image_tag
앞에cl
태그를 추가했다cl_image_tag
photo_uploader.rb
파일은 다음과 같습니다
class PhotoUploader < CarrierWave::Uploader::Base
include Cloudinary::CarrierWave
# storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
내 게시물 컨트롤러 파일은 다음과 같습니다
class PostsController < ApplicationController
before_action :authenticate_user!, only: [:new, :create]
before_action :is_owner?, only: [:edit, :update, :destroy]
def index
@posts = Post.all.order('created_at DESC').includes(:user, comments: :user).paginate(:page => params[:page], :per_page => 10)
end
def new
@post = Post.new
end
def create
@post = current_user.posts.create(post_params)
if @post.valid?
flash[:success] = "Your photo has been successfully posted!"
redirect_to root_path
else
flash[:alert] = "Woops! Looks like there has been an error!"
render :new, status: :unprocessable_entity
end
end
def edit
@post = Post.find(params[:id])
end
def update
@post = Post.find(params[:id])
@post.update(post_params)
if @post.valid?
flash[:success] = "Your post has been successfully updated!"
redirect_to root_path
else
flash[:alert] = "Woops! Looks like there has been an error!"
render :edit, status: :unprocessable_entity
end
end
def show
@post = Post.find(params[:id])
end
def destroy
@post = Post.find(params[:id])
@post.destroy
flash[:success] = "The post was successfully deleted!"
redirect_to root_path
end
private
def is_owner?
redirect_to root_path if Post.find(params[:id]).user != current_user
end
def post_params
params.require(:post).permit(:user_id, :photo, :description)
end
end
가장 큰 문제 그 문은 else
create model
인데 inste가 실행됩니다. valid
의 광고 가 어떻게 "사용자"를 선택
'@ post'의 유효성 검사 오류는 무엇입니까? 로그/경고'@ post.errors.full_messages'? – Rahul
사진 업로드 후 오류 : 'Woops! 오류가있는 것처럼 보입니다! ' – Achyut
유효성 검사 오류가 아니라 하드 코딩 된 오류 메시지입니다. 스크린 샷을 보면서 사진을 업로드하는 것을 잊었습니까? – Rahul