class Business < ApplicationRecord ......... belongs_to :user has_many :likes
class Like < ApplicationRecord belongs_to :user belongs_to :business
end
class User < ApplicationRecord has_many :likes
<%= button_tag "Like", data: {reflex: "click->Likes#like", id: @business.id} %>
class LikesReflex < ApplicationReflex def like business = Business.find(element.dataset[:id]) business.likes.find_or_create_by(user: current_user)
......
user.users_posts user.liked_posts,
undefined method `to_sgid
@liked_post.each do |post|%> link_to "Unfollow",posts_like_path(post, id: @liked_post.to_sgid(expires_in: 1.hour)),method: :delele
def user_profile @user= current_user @posts = @user.posts.all @liked_post = @user.liked_post end
link_to "Unfollow",post_like_path(post, id: post.to_sgid(expires_in: 1.hour)),method: :delete
PG::ForeignKeyViolation: ERROR: update or delete on table "posts" violates foreign key constraint "fk_rails_fbe88b52fa" on table "users_posts" DETAIL: Key (id)=(10) is still referenced from table "users_posts".
def destroy post = Post.friendly.find(params[:post_id]) user_post = GlobalID::Locator.locate_signed(params[:id]) user_post.destroy! redirect_to post_path(post), alert: "unfollow" end