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