我正在尝试使acts_as_follower工作,但是我缺少一些东西。一个用户应该能够关注另一个用户。

我加了宝石:

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


在我的用户模型中,我添加了:

acts_as_follower
acts_as_followable


我创建的用户控制器如下所示:

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


我的路线:

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


现在在路线中,我必须添加成员:follow =>

member do
  get :follow
end


但是我被困在这一点上。我尝试了一些变体,而跟随用户的链接是:

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


这给了我错误->

undefined method `follow_users_path' for #<#<Class:0x007fb4da78e920>:0x007fb4db3facb8>

最佳答案

解决方案是创建一个user resource,现在可以正常使用=>

resources :users do
    member do
      get :follow
      get :unfollow
    end
  end

关于ruby-on-rails - 充当关注者设置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20935772/

10-12 00:48