質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

0回答

1056閲覧

プロフィール画像の変更が反映されない

Yn_26247

総合スコア16

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2020/08/11 13:00

編集2020/08/11 13:12

ガチガチの初心紗です。
プロフィール画像変更できる機能を追加したいのですが

edit.html.erb

<% if @user.errors.any? %> <div> <ul style="color: red"> <% @user.errors.full_messages.each do |message| %> <h3><%= @user.errors.count %> errors prohibited this obj from being saved</h3> <li><%= message %></li> <% end %> </ul> </div> <% end %> <div class="container"> <div class="row"> <div class='col-xs-3'> <h1>User info</h1> <table class='table'> <%= form_for(@user) do |f| %> <label>Name</label> <%= f.text_field :name, id: :user_name %></br> <label>image</label></br> <%= f.attachment_field :profile_image, placeholder: "プロフィール画像", class: "user-edit-form" %></br> <lavel>introduction</lavel> <%= f.text_area :introduction, id: :user_introduction %></br> </table> <div class='row'> <%= f.submit "Update User" %></br> </div> </div> </div> <% end %>

コントローラー

def edit @user = User.find(params[:id]) if @user != current_user redirect_to user_path(current_user) end end def update @user = User.find(params[:id]) if @user.update(user_params) flash[:notice] = "Book was successfully updated." redirect_to user_path(@user) else render "edit" end end

_profile.html.erb

<h1>User info</h1> <div class="profile-container"> <table class="table"> <thead> <tr> <div class="profile-container"> <%= attachment_image_tag user, :profile_image, :fill, 60, 60, fallback: "no_image.jpg", class: "img-circle pull-left profile-thumb" %> </div> </tr> <tr> <th>name</th> <th><div class="profile-name"><%= user.name %></div></th> </tr> <tr> <th>introduce</th> <th><div class="profile-introduction"><%= user.introduction %></div></th> </tr> <!-- <button type="button" class="btn btn-primary btn-block"> --> </thead> </table> </div> <div class="botan"> <%= link_to "", edit_user_path(current_user), class: "col-xs-12 btn btn-default glyphicon glyphicon-wrench" %><br> </div>

イメージ説明

としているのですが、画像を変更することができません
アドバイスいただけると幸いです

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問