LoginSignup
9
9

More than 5 years have passed since last update.

Rails CarrierWaveを使ってみた

Last updated at Posted at 2015-05-07

Rails 超お手軽な画像アップローダー CarrierWave の使い方
を参考にcarrierwaveを実装しました。

注意点
*ImageMagickのインストールに関して
yumでインストール出来ない(Macにデフォルトでyumはない)

MacでImageMagickがインストールできない問題
を参考にして
$ brew install libpng
$ brew install imagemagick
brew link は単に有効化。ここではinstallを使った。
これでオーケー。

登録される画像の場所
/public/uploads/user/image

no_image等の画像はここに入れる
/app/assets/images

新規登録時のプロフィール画像を設定

/views/devise/registrations/new.html.erbに

<div class="field">
<%= f.label :image %><br />
<%= f.file_field :image %>
</div>  

を追記して、新規登録時にプロフィール画像の設定を追加。

app/controllers/application_controller.rbに

def configure_permitted_parameters
end

の中に

devise_parameter_sanitizer.for(:sign_up) << :image

を追加。

プロフィール画像の編集設定

下記を追記。

/views/devise/registrations/edit.html.erb
<div class="field">
<%= f.label :image %><br />
<%= f.file_field :image %>
</div>
app/controllers/application_controller.rb

def edit
super
end

def update
super
end

private

def configure_permitted_parameters
  devise_parameter_sanitizer.for(:account_update) do |u|
    u.permit(:name, :email, :password, :password_confirmation, :current_password, :image)
  end
end
9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9