###前提・実現したいこと
paperclipを使用して、画像投稿をできるようにしたいです。
###発生している問題・エラーメッセージ
写真を添付して保存ボタンを押すと以下のエラーが出ます。
Could not run the `identify` command. Please install ImageMagick.
こちらの記事を参考に進めたのですが、うまく行きません。。。
imagemagickはインストールしています。
ただ、インストールまで一悶着ありました。
最初にbrewでimagemagickをインストールすると失敗しましたので、brewをupdateしました。
その後、imagemagickをインストールすると成功しました。
$ brew install imagemagick★失敗★ Error: Unsupported special dependency :perl Please report this bug: ・・・省略・・・ $ brew update $ which convert★成功★ /home/ubuntu/.linuxbrew/bin/convert $ brew install imagemagick Warning: imagemagick-7.0.5-0 already installed
###該当のソースコード
【config/development.rb】
Paperclip.options[:image_magick_path] = "/usr/local/bin" Paperclip.options[:command_path] = "/usr/local/bin"
def create @micropost = current_user.microposts.build(micropost_params) @micropost.save! end private def micropost_params params.require(:micropost).permit(:title, :lecture, :professor, :price, :content, :user_id, :photo) end
【micropost.rb】
# photoをattachファイルとする。stylesで画像サイズを定義できる has_attached_file :photo, styles: { medium: "300x300>", thumb: "100x100>" } # ファイルの拡張子を指定(これがないとエラーが発生する) validates_attachment :photo, content_type: { content_type: ["image/jpg", "image/jpeg", "image/png", "image/gif"] }
ご経験ある方ご指摘お願いします!
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。