我正在尝试在我的应用程序中实现类似于 Twitter 的关注者系统。我正在实现 Michael Hartl 的 Rails 教程中解释的 Follower 系统:
http://ruby.railstutorial.org/chapters/following-users
完成示例后,我注意到一个问题:
转到 /users/(id)/following 或 /users/(id)/followers 会显示以下错误消息:
Unknown action
The action 'following' could not be found for UsersController
或者
Unknown action
The action 'followers' could not be found for UsersController
这些错误让我感到困惑的是,我确实在 UsersController 中定义了这些操作:
def following
@title = "Following"
@user = User.find(params[:id])
@users = @user.followed_users.paginate(page: params[:page])
render 'show_follow'
end
def followers
@title = "Followers"
@user = User.find(params[:id])
@users = @user.followers.paginate(page: params[:page])
render 'show_follow'
end
这是我的 routes.rb 文件,以防万一出现问题:
AppName::Application.routes.draw do
#get "users/index"
#get "users/show"
authenticated :user do
root :to => 'home#index'
end
root :to => "home#index"
devise_for :users
resources :users do
member do
get :following, :followers
end
end
resources :works
resources :relationships, only: [:create, :destroy]
end
附加信息:我正在使用设计来处理用户身份验证。
固定的:
问题是在用户控制器中放置以下和后续操作。