Rails Active_Storageを確認画面を挟んで表示・POSTしたい
Rails Active_Storageを確認画面を挟んで表示・POSTしたいです
発生している問題(確認画面で画像が表示されない)
確認画面で画像がうまく表示されません
view edit
<%=form_with(model: @userprofile, url: {action: 'confirm'}, method: 'put', local: true) do |f| %> <div class="icon mx-auto"> <%= image_tag 'icon_profile.svg',{class: "icon mx-auto icon_avatar",id: 'preview'}%> </div> <%= f.file_field :image, accept: 'image/*', onchange: 'previewImage(this);' %> <div class="icon mx-auto"> <%= image_tag 'icon_profile.svg',{class: "icon_avatar"}%> </div> <div class="row"> <div class="col-md-9"></div> <%= link_to '戻る', :back, class: 'btn_back' %> <%= f.submit '確認', class: 'btn_dec' %> </div> <% end %>
view confirm
<div class="icon mx-auto"> <% if @user.user_profile.image.attached? %> <%= image_tag @user.user_profile.image ,{class: "icon_avatar"} %> <% else %> <%= image_tag 'icon_profile.svg',{class: "icon_avatar"} %> <% end %> </div> <p><%= @user.user_profile.image.present? ? @user.user_profile.image.filename : "添付ファイルなし" %></p> <div class="row"> <div class="col-md-9"></div> <%= link_to '戻る', :back, class: 'btn_back' %> <%= form_with(model: @userprofile ,url: user_path(@userprofile), method: 'put', local: true) do |f| %> <%= f.hidden_field :image %> <%= f.hidden_field :staff_name %> <%= f.hidden_field :user_authority, :value => @user.user_authority %> <%= f.hidden_field :partner_code %> <%= f.hidden_field :email_address %> <%= f.submit '保存', class: 'btn_dec' %> <% end %> </div>
controller
def edit @title = 'ユーザー変更' @user = User.find(params[:id]) @userprofile = @user.user_profile end def confirm logger.debug "************************: [#{params.inspect}]" @user = User.find(params[:id]) @user.user_authority = users_params[:user_authority] @user.user_profile.image = users_params[:image] @user.user_profile.email_address = users_params[:email_address] @user.user_profile.partner_code = users_params[:partner_code] @user.user_profile.staff_name = users_params[:staff_name] @userprofile = @user.user_profile logger.debug "************************: [#{@user.inspect}]" end def update @title = 'ユーザー変更' @user = User.find(params[:id]) # @userprofile = @user.user_profile logger.debug "************************: [#{params.inspect}]" logger.debug "************************: [#{users_params.inspect}]" @user.user_authority = users_params[:user_authority] @user.user_profile.image = users_params[:image] @user.user_profile.email_address = users_params[:email_address] @user.user_profile.partner_code = users_params[:partner_code] @user.user_profile.staff_name = users_params[:staff_name] # byebug if @user.user_profile.save! && @user.save! post = e.record post.image = nil redirect_to users_path(@userprofile),notice: '更新されました' else flash.now[:error] = '更新できませんでした' render :edit end end private def users_params # puts "------------------" # puts users_params # puts "-----------------" params.require(:user_profile).permit(:user_authority,:image, :email_address, :partner_code, :staff_name) end
### 実行したこと
あなたの回答
tips
プレビュー