我试图让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 =&gt;
member do
get :follow
end
但我仍然坚持这一点。我尝试了一些变体,我关注用户的链接是:
<%= link_to "Follow", follow_user_path(@user)%>
这给了我错误 - &gt;
undefined method `follow_users_path' for #<#<Class:0x007fb4da78e920>:0x007fb4db3facb8>
答案 0 :(得分:3)
解决方案是创建一个user resource
,它现在完美地工作=&gt;
resources :users do
member do
get :follow
get :unfollow
end
end