ruby 2.3.1
Rails 5.2.2
Railsでユーザー投稿型の動的サービスを作っています。
サービス自体はほぼほぼ出来上がったのですが、表題の件で詰まっています。
◾️知りたいこと
Railsのconfig.cache_classes = trueで動的サービスを扱う場合、以下のような処理を別途実装する必要あるのでしょうか?
・db更新時にフラグか何かを立てる
・controllerやviewでdb更新があるか確認する
検索の仕方が悪いのか、なかなか解決策が見つかりません。
ヒントだけでもいただけると幸いです。
◾️事象
config.cache_classes = trueを設定すると、更新(ex.ユーザープロフに顔写真を投稿など)しても、更新内容が反映されない。
※本番、開発環境の両方で起きています。
※config.cache_classes = falseにすると問題なく更新内容は反映されます。
※サーバー再起動すると更新内容は反映されますが、再度更新した際にその内容は反映されません。
◾️詳細
簡略化していますが、以下のようなページでサービスが構成されます。
・index
・show
・edit
editの更新完了時にshowにリダイレクトさせています。
その場合、showは更新内容が反映されますが、indexには反映されません。
indexのimg srcは変更前のパスを指し、その画像が既にdbから削除された状態でもキャッシュで表示され続けます。
追記
controllerとviewは以下です。
ーーーーーーーーーー GroupsController ーーーーーーーーーー def index if user_signed_in? @groups = current_user.groups.includes([{next_author: [user: :user_image]} ]) else @groups = [] end end ーーーーーーーーーー UsersController ーーーーーーーーーー def show @user = User.find(params[:id]) @image = @user.user_image end def edit @user = User.find(params[:id]) @image = @user.user_image if current_user.id == @user.id @user.build_user_image if @user.user_image.nil? else redirect_to action: :show, id: @user end end def update @user = User.find(params[:id]) if @user.update(user_params) flash[:success] = t('flash.success_user_update') redirect_to action: :show, id: current_user.id else flash[:warning] = t('flash.fail_user_update') render :edit end end
説明足りていませんでしたが、userを更新し、group indexに表示させる仕様です。
ーーーーーーーーーー Group index ーーーーーーーーーー <% if user_signed_in? %> <%= render partial: "group", collection: @groups, cached: true %> <% if @groups.length < $group_max_num %> <%= render 'group_new' %> <% end %> <% else %> <%= render 'group_new' %> <% end %> ーーーーーーーーーー Partial ーーーーーーーーーー <div class="groupdiary-wrap" diary-term="<%= $diary_term %>"> <div class="row groupdiary-middle"> <div class="col-12 text-center">next author</div> <div class="col-6 mx-auto text-center"> <%= link_to user_path(group.next_author.user) do %> <% if group.next_author.user.user_image.blank? %> <%= image_tag 'user-blue.png', class: 'global-icon next-author-icon circle'%> <% else %> <%= image_tag(group.next_author.user.user_image.image.url, class: "global-icon next-author-icon circle") %> <% end %> <% end %> </div> </div> </div>
回答1件
あなたの回答
tips
プレビュー