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

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

新規登録して質問してみよう
ただいま回答率
85.50%
Devise

Deviseとは、Ruby-on-Railsの認証機能を追加するプラグインです。

Ruby on Rails

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

Q&A

解決済

1回答

4359閲覧

attachment_image_tagでプロフィール画像が表示できない

退会済みユーザー

退会済みユーザー

総合スコア0

Devise

Deviseとは、Ruby-on-Railsの認証機能を追加するプラグインです。

Ruby on Rails

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

0グッド

0クリップ

投稿2020/01/05 16:37

ユーザー情報の編集画面でプロフィールを変更できるようにしたいのですが、登録されません。
users/edit.html.erbで編集し、users/show.html.erbで表示したいです。
エラーは出ておりません。
ログイン機能にはdevise、gemでrefileを使用しています。

models/user.rb class User < ApplicationRecord # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable has_many :books, dependent: :destroy attachment :profile_image validates :name, uniqueness: true, presence: true, length: { minimum: 2, maximum: 20 } end
users/users_controller.rb class UsersController < ApplicationController def index @book = Book.new @users = User.page(params[:page]).reverse_order end def show @user = User.find(params[:id]) @book = Book.new @books = @user.books.page(params[:page]).reverse_order end def edit @user = User.find(params[:id]) end def update @user = User.find(params[:id]) @user.update(user_params) redirect_to user_url(@user.id) end private def user_params params.require(:user).permit(:name, :introduction, :profile_image_id) end end
users/edit.html.erb <%= render 'shared/header' %> <h2 class="header-space">User info</h2> <%= form_for(@user) do |f| %> <div class="field"> <%= f.label :Name %><br/> <%= f.text_field :name, autofocus: true, autocomplete: "name" %> </div> <div class="form-group has-icon user-edit"> <%= f.label :Image %><br/> <%= f.attachment_field :profile_image, placeholder: "Image", class: "user-edit-form" %> </div> <div class="field user-edit"> <%= f.label :Introduction %><br/> <%= f.text_area :introduction, autofocus: true, autocomplete: "introduction" %> </div> <div class="actions"> <%= f.submit "Update" %> </div> <% end %> <%= render 'shared/footer' %>
users/show.html.erb <%= render 'shared/header' %> <div class="header-space"> <div class="container"> <div class="row"> <div class="col-xs-3"> <h3>User info</h3> <%= attachment_image_tag @user, :profile_image, :fill, 100, 100, format: 'jpg', fallback: "no_image.jpg", size:'100x100' %> <table class="table"> <tr>    <th><h4>name</h4></th>    <th><%= @user.name %></th>   </tr>   <tr>    <th><h4>introduction</h4></th>    <th><%= @user.introduction %></th>    </tr> </table> <% if @user == current_user %> <div class="row"> <%= link_to edit_user_path(@user), class: "col-xs-12 btn btn-default" do %> <i class="fa fa-wrench"></i> <% end %> </div> <h3>New book</h3> <%= form_for @book do |f| %> <div class="book-form row"> <label for="book_title"><h4>Title</h4></label> <%= f.text_field :title, :class => 'col-xs-12' %> </div> <div class="book-form row"> <label for="book_body"><h4>Opinion</h4></label> <%= f.text_area :body, :class => 'col-xs-12' %> </div> <div class="row"> <%= f.submit 'Create Book', :class => 'col-xs-12 btn btn-primary' %> </div> <% end %> <% end %> </div> <div class="col-xs-9"> <h3>Books</h3> <table class="table table-hover table-inverse"> <thead> <tr> <th></th> <th><h4>Title</h4></th> <th><h4>Opinion</h4></th> </tr> </thead> <% @books.each do |book| %> <tbody> <tr> <td><%= attachment_image_tag book.user, :profile_image, :fill, 40, 40, format: 'jpeg', fallback: "no_image.jpg", size:'40x40' %></td> <td><%= link_to book.title, book_path(book.id) %></td> <td><%= book.body %></td> </tr> </tbody> <% end %> </table> </div> </div> </div> </div> <%= render 'shared/footer' %>

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

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

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

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

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

guest

回答1

0

ベストアンサー

コードの記述ミスとImageMagickインストールしていませんでした。

def update内
×redirect_to user_url(@user.id)
○redirect_to user_path(@user.id)

user_params内
×:profile_image_id
○:profile_image

ImageMagick
$ sudo apt-get update
$ sudo apt-get -y install imagemagick libmagick++-dev

投稿2020/01/11 14:46

退会済みユーザー

退会済みユーザー

総合スコア0

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問