railsでログイン機能についての問題です。
ゲストログインをするとマイページにユーザーアイコンが表示されるように設定しています。
app/assets/images/内の画像ファイルを読み込んで表示させています。
この画像ファイルの中身を変えてもlocalhostでは変更が反映されず、herokuの本番環境では画像じたいが表示されません。
localhostで画像の変更が反映されていないのが、herokuのも影響しているのだと思います。
lsof -wni tcp:3000
のコマンドでlocalを一度切断して、新しくloxalhostを立ち上げても画像の変更が反映されません。
試しに他の文章を変えてみると、それは変更が反映されます。
その画像の変更だけが反映されません。
いかが関係ありそうなファイルとコードです。
app/views/public/show.html.erb
1<h2 class="font-weight-bold mb-3">mypage</h2> 2 <!--プロフィール画像--> 3 <%= image_tag @end_user.get_profile_image(150,150), class: "rounded-circle img" %> 4 <!--ユーザー名--> 5 <p><%= @end_user.name %></p>
app/models/user.rb
1# プロフィール画像の設定 2 has_one_attached :profile_image 3 4 # プロフィール画像(デフォルト)の設定 5 def get_profile_image(width, height) 6 unless profile_image.attached? 7 file_path = Rails.root.join("app/assets/images/pro.jpg") 8 profile_image.attach(io: File.open(file_path), filename: "default-image.jpg", content_type: "image/jpeg") 9 end 10 profile_image.variant(resize_to_limit: [width, height]).processed 11 end 12 13 # ゲストログインの設定 14 def self.guest 15 find_or_create_by!(name: "guestuser", email: "guest@example.com") do |user| 16 user.password = SecureRandom.urlsafe_base64 17 user.name = "guestuser" 18 end 19 end
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。