Reputation: 3100
I'm trying to implement a Follower system similar to Twitter in my app. I'm implementing the Follower system explained in Michael Hartl's Rails Tutorial:
http://ruby.railstutorial.org/chapters/following-users
I have noticed an issue after completing the example:
Going to /users/(id)/following or /users/(id)/followers displays the following error messages:
Unknown action
The action 'following' could not be found for UsersController
or
Unknown action
The action 'followers' could not be found for UsersController
What puzzles me about these errors is that I did define these actions in the 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
Here is my routes.rb file just in case the issue lies there:
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
Additional information: I'm using Devise to handle user authentication.
FIXED:
The issue was the placement of the following and followed actions in the Users Controller.
Upvotes: 1
Views: 676
Reputation: 11
resources :users do
member do
get :following
get :followers
end
end
the above routes work, and provide following_user_path
and followers_user_path
routes respectively
Upvotes: 1
Reputation: 4157
In your config/routes.rb
, the member actions must be one per line:
resources :users do
member do
get :following
get :followers
end
end
See also http://guides.rubyonrails.org/routing.html#adding-more-restful-actions
Upvotes: 1