私は最近、私のRailsアプリケーションで、画像のクラウドストレージをcarrierrwaveと統合してクラウドに変更しました。それは完璧に動作しますが、画像をアップロードした後に写真が空白であるというエラーが表示されるという問題があります。エラーが表示されているにもかかわらず、私は手作業でルートURLを再ロードしました。その時点で写真はすでにアップロードされていました...問題は新しい投稿と編集の投稿のみですが、プロフィール画像を更新していて、私はsimple_form
を使って写真をアップロードしました。私は何が欠けている、問題を解決するために私を助けてください。写真をアップロードした後のエラーページ:This is the screenshotキャリアウェーブをキャリアウェーブに変更した後、レールアプリに写真をアップロードした後にエラーが表示されるのはなぜですか?
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
が実行されているvalid
の広告。 どのように私はこの問題を解決することができ、私を助けて...
'@ post'の検証エラーは何ですか?ログ/アラート '@ post.errors.full_messages'? – Rahul
写真をアップロードした後のエラーは: 'Woops!エラーが発生したようです! ' – Achyut
これは検証エラーではなく、ハードコードされたエラーメッセージです。あなたのスクリーンショットを見て、あなたは写真をアップロードするのを忘れましたか? – Rahul