I have a relationship table with followed_id, follower_id, and status. I am using "has many through" in my user model to create the association. A user has many following through and is following many through a reverse relationship. The status defaults to "requested" when a user follows another user.
So then a user has a list of their followers and each has a status of "requested".
What I need in this list of followers is a link_to with a put method or a form that just finds that relationship and updates the status string to "approved". It seems like it would be pretty easy but I have been searching for days and cannot figure it out. This is what I have so far:
In the users_controller this the action to change the status from "requested" to "approved":
def activate
@user = User.find(params[:id])
params[:status] = {:status => 'approved'}
@user.status = params[:user][:status]
@user.save
render 'show_followers'
end
this is in the users_controller to list the followers:
def followers
@title = "Followers"
@user = User.find(params[:id])
@users = @user.followers.paginate(:page => params[:page])
render 'show_followers'
end
this is where I define status which is probably not right in user.rb model
def status
Relationship.status.find_by_follower_id(self)
end
and this is the page where I show the followers:
<% unless @users.empty? %>
<% @users.each do |user| %>
<tr>
<td><%= image_tag user.avatar.url(:thumb) %></td>
<td><%= user.full_name %></td>
<td><%= user.company %></td>
<td><%= user.approval.status %></td>
<%end%>
<td><%= form_for @user, url: activate_user_path(@user), :html => { :method => :put } do |f| %>
<%= f.submit "approve" %>
<% end %>
</td>
</tr>
<%= will_paginate @users %>
<% end %>
does anyone know how I can just update that string in Relationship table to "approved"?