私はruby on railsをprogateで学習中で、その応用としてCarrierWaveを使って
画像投稿機能を実装してみたいのですが画像が表示されません。誰か教えていただけないでしょうか?
routes
1Rails.application.routes.draw do 2 get 'users/index' 3 #get 'home/top' 4 5 get "login" => "users#login_form" 6 post "login" => "users#login" 7 post "logout" => "users#logout" 8 9 post "users/:id/update" => "users#update" 10 get "users/:id/edit" => "users#edit" 11 post "users/create" => "users#create" 12 get "signup" => "users#new" 13 get "users/index" => "users#index" 14 get "users/:id" => "users#show" 15 post "users/:id/destroy" => "users#destroy" 16 17 18post "/posts" => "posts#create" 19 20 get "posts/index" => "posts#index" 21 get "posts/new" => "posts#new" 22 get "posts/:id" => "posts#show" 23 24 post "posts/create" => "posts#create" 25 26 get "posts/:id/edit" => "posts#edit" 27 post "posts/:id/update" => "posts#update" 28 post "posts/:id/destroy" => "posts#destroy" 29 30 31 get "/" => "home#top" 32 get "/about" => "home#about" 33 34 35 36 match '*unmatched',to: 'application#route_not_found',via: :all 37 # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html 38end 39
index
1<div class="main posts-index"> 2 <div class="container"> 3 <% @posts.each do |post| %> 4 <div class="posts-index-item"> 5 <div class="post-left"> 6 <!-- ユーザーの画像が表示されるように、以下のsrcに値を追加してください --> 7 8 <img src="<%= "/#{post.user.image_name}" %>"> 9 </div> 10 <div class="post-right"> 11 <div class="post-user-name"> 12 <!-- link_toメソッドを用いて、ユーザー詳細ページへのリンクを作成してください --> 13 14 </div> 15 <%= link_to(post.content, "/posts/#{post.id}") %> 16 17 <% @posts.each do |post| %> 18 <tr> 19 <td><%= image_tag post.image.to_s %></td> 20 </tr> 21 <% end %> 22 23 </div> 24 25 </div> 26 27 <% end %> 28 </div> 29</div> 30
試したこと
https://qiita.com/hmmrjn/items/24f3b8eade206ace17e2の通りに
route.rbを修正してエラーが出なくなった。
あなたの回答
tips
プレビュー