前提・実現したいこと
ここに質問の内容を詳しく書いてください。
プログラミング勉強のため今、チャットアプリを作っています。
工程の中でユーザー編集ページを作っている際に躓いています。
発生している問題・エラーメッセージ
プロフィール画像ファイルを選択してもデフォルトで設定している画像が表示されたままで選択したプロフィール画像が表示されません。
HTML,CSSはまだ未実装です。
該当のソースコード
#user_controller.rb
class UsersController < ApplicationController
def edit
@user = User.find(params[:id])
end
def update
if current_user.update(user_params)
redirect_to root_path
else
render :edit
end
end
def show
user = User.find(params[:id])
@name = User.name
@image = User.profile_image
end
private
def user_params
params.require(:user).permit(:name, :email, :profile_image)
end
#edit.html.erb
<h2>Edit <%= resource_name.to_s.humanize %></h2><%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
<%= render "devise/shared/error_messages", resource: resource %>
<%= form_for(@user) do |f| %>
<% if @user.profile_image? %>
<%= image_tag @user.profile_image_url(:thumb) %>
<% else %>
<%= image_tag "/assets/iccon.png", size: '200x200' %>
<% end %>
<button type="button">
<%= f.file_field :profile_image, accept: 'image/jpeg,image/gif,image/png' %>
</button>
<% end %>
<%= link_to "Back", :back %>
試したこと
調べて見たのですが解決策が見つからなかったので質問させていただきました。
回答いただけると幸いです。
CarreirWave, MiniMagick, ImageProcessing はインストールしている状態です。
補足情報(FW/ツールのバージョンなど)
Ruby 2.6.5
Rails 6.0.3.5
あなたの回答
tips
プレビュー