前提・実現したいこと
メニューバーのマイページリンクからshow.html.erbに飛びたい
発生している問題・エラーメッセージ
ログイン中にマイページリンクをクリックした際、
と出ます。
該当のソースコード
users.controller.rb
def show @user =User.find(params[:id]) @post_images = @user.post_images end
user.rb
class User < ApplicationRecord # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable has_many :post_images, dependent: :destroy has_many_attached :profile_image def get_profile_image(width, height) unless profile_image.attached? file_path = Rails.root.join('app/assets/images/sample-author1.jpg') profile_image.attach(io: File.open(file_path), filename: 'default-image.jpg', content_type: 'image/jpeg') end profile_image.variant(resize_to_limit: [width, height]).processed end end
application.html.erb
・ ・ ・ <li> <%= link_to '投稿フォーム', new_post_image_path %> </li> <li> <%= link_to 'マイページ', user_path(current_user.id) %> </li> <li> <%= link_to "ログアウト", destroy_user_session_path, method: :delete %> </li> ・ ・ ・
show.html.erb
<div> <h3><%= @user.name %></h3> <%= image_tag @user.get_profile_image(100,100) %> </div> <% @post_images.each do |post_image| %> <div> <%= link_to post_image_path(post_image.id) do %> <%= image_tag post_image.get_image %> <% end %> <p>投稿ユーザー画像:<%= image_tag post_image.user.get_profile_image(100,100) %></p> <p>ショップ名:<%= post_image.shop_name %></p> <p>説明:<%= post_image.caption %></p> <p>ユーザーネーム:<%= post_image.user.name %></p> </div> <% end %>
まだ回答がついていません
会員登録して回答してみよう