###前提・実現したいこと
他モデル間でのフォロー機能にajaxを実装したいです。
followの部分は実装できています。(たぶん)
###発生している問題・エラーメッセージ
unfollow(associates#destroy)でもajaxを実装しているつもりができてません。
【associates_controller】
class AssociatesController < ApplicationController before_action :logged_in_user def create @shop = Shop.find(params[:shop_id]) @associate = current_user.associates.build(shop: @shop) @associate.save redirect_to @shop end def destroy @associate = current_user.associates.find_by!(shop_id: params[:shop_id]) @associate.destroy redirect_to @shop end end
↑destroyのredirected_toが反応していないような気が…
【associates/_associate_links】
<div id="follow_form"> <% if @shop.associated_by? current_user %> <%= link_to 'unfollow', shop_associates_path(@shop.id), method: :delete, remote: true %> <% else %> <%= link_to 'follow', shop_associates_path(@shop.id), method: :post, remote: true %> <% end %> </div>
【associates/create.js.erb】
$('#follow_form').html('<%= escape_javascript(render("associates/associate_links")) %>');
【associates/destroy.js.erb】
$('#follow_form').html('<%= escape_javascript(render("associates/associate_links")) %>');
ちなみにリンクはshowページに貼ってあります。
【shops/show】
<% if user_signed_in? %> <%= render 'associates/associate_links'%> <% end %>
###補足情報(言語/FW/ツール等のバージョンなど)
ShopとUser間におけるフォロー機能になっています。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/10/20 12:32
2016/10/20 12:43
2016/10/20 12:57