Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Acts as follower Set Up

I'm trying to get acts_as_follower working but i'm missing something. A user should be able to Follow another User.

I added the Gem :

gem "acts_as_follower", '~> 0.2.0' #0.2.0 for Rails 4

In my User model i added :

acts_as_follower
acts_as_followable

The User Controller i created looks like this :

class UsersController < ApplicationController

  def show
    @user = User.find(params[:id])
  end

  def follow
    @user = User.find(params[:id])
    current_user.follow(@user)
    redirect_to :back
  end

end

My routes :

App::Application.routes.draw do

  root 'screens#index'

  devise_for :users
  get 'u/:id' => 'users#show', as: :user

  resources :screens, :path => 's' do
    member do
      get :like
      get :unlike
    end
  end


  get "pages/home"
  get "about" => "pages#about"
  get "users/show"

end

now in the routes i have to add the member :follow =>

member do
  get :follow
end

But i'm stuck at this point. I tried a few variations and my link to follow a User is :

<%= link_to "Follow", follow_user_path(@user)%>

and this is giving me the error ->

undefined method `follow_users_path' for #<#<Class:0x007fb4da78e920>:0x007fb4db3facb8>
like image 426
Mini John Avatar asked Oct 27 '25 03:10

Mini John


1 Answers

The Solution was to create a user resource, it works perfectly now =>

resources :users do
    member do
      get :follow
      get :unfollow
    end
  end
like image 158
Mini John Avatar answered Oct 29 '25 18:10

Mini John



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!