に、私は、次の宝石を使用しています保存されません。ペーパークリップは、データベース
モデル/ user.rb
class User < ApplicationRecord
# This method associates the attribute ":avatar" with a file attachment
has_attached_file :avatar, styles: {
thumb: '100x100>',
square: '200x200#',
medium: '300x300>'
}
# Validate the attached image is image/jpg, image/png, etc
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
end
マイグレーション
class AddAvatarToUsers < ActiveRecord::Migration[5.1]
def self.up
add_attachment :users, :avatar
end
def self.down
remove_attachment :users, :avatar
end
end
コントローラ/ users_controller.rb
class UsersController < ApplicationController
def edit
@user = User.find_by(id: params[:id])
end
def update
@user = User.find(params[:id])
if @user.update(user_params)
flash[:notice] = "Edit successfully"
redirect_to("https://stackoverflow.com/users/#{@user.id}")
end
end
private
def user_params
params.require(:user).permit(:avatar, :name, :email, :phone_number, :description, :college_name)
end
end
イメージアバターがデータベースに保存されていないのはなぜですか? データベース列を追加する必要がありますか?私は何をすべきか?私はこの問題を解決するのに役立つすべての入力を感謝します。
ユーザーを更新しようとすると、特定のエラーメッセージが表示されますか? – michaeldever
いいえ、私はそうではありません。エラーメッセージは表示されません。 –