vendredi 16 juin 2017

How can I make follow form work with a list

I have a relationship model that follow users back n forth now it works very well when I use it in users#show in my view just like this screenshot

enter image description here

now this works good but what I have is a list of users.. and with that list I want to render similar type of follow form next to every item in list

here is the screenshot for reference

enter image description here

but of course this doesn't work because in my relationship controller I am finding user/amitian to follow with their id in params[:id] as in show page i have it but in my list page i don't

here is the code in controller for reference

def create
    @amitian = Amitian.find(params[:followed_id])
    current_amitian.follow(@amitian)
     respond_to do |format|
      format.html { redirect_to @amitian }
      format.js
    end
  end

  def destroy
    @amitian = Relationship.find(params[:id]).followed
    current_amitian.unfollow(@amitian)
     respond_to do |format|
      format.html { redirect_to @amitian }
      format.js
    end
  end

is there any solution for this so that I can render a follow_form in my listpage it doesn't matter even if i have to render a new follow_form.. it just i want follow mechanism to work even from list page rather than only from show page of every user.

Aucun commentaire:

Enregistrer un commentaire