1
我目前無法列出current_user正在關注或正在關注的所有用戶。我嘗試了至少6種不同的方法讓Users_Controller在視圖中使用方法。接收未定義的acts_as_follower方法all_following和all_follows
這兩種方法/觀點造成的問題將放在以下
def following
@user_following = User.all_following(:order => 'created_at DESC').paginate(page: params[:page])
end
def followers
@user_followers = User.all_follows(:order => 'created_at DESC').paginate(page: params[:page])
end
用戶關注查看
<% if @user_followers.any? %>
<% @user_followers.each do |user| %>
<%= link_to(image_tag(user.avatar.url(:thumb)), user_path(user)) %>
<%= user.username %>
<%= user.followers_count %>
<% end %>
<% end %>
用戶以下幾種觀點
<% if @user_following.any? %>
<% @user_following.each do |user| %>
<%= link_to(image_tag(user.avatar.url(:thumb), user_path(user)) %>
<%= user.username %>
<% end %>
<% end %>
堆棧跟蹤誤差
Processing by UsersController#followers as HTML
Parameters: {"id"=>"john280"}
User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT 1 [["id", 3]]
User Load (0.0ms) SELECT "users".* FROM "users"
Completed 500 Internal Server Error in 5ms (ActiveRecord: 0.0ms)
NoMethodError (undefined method `all_follows' for #<User::ActiveRecord_Relation:0xd616898>):
app/controllers/users_controller.rb:64:in `followers'
Route.rb
resources :users, only: [:get, :show, :index, :edit, :update], path: '' do
member do
get :follow
get :unfollow
get :followers
get :following
end
end
/:id/follow(.:format) follow_user_path
/:id/unfollow(.:format) unfollow_user_path
/:id/followers(.:format) followers_user_path
/:id/following(.:format) following_user_path
嗯,好的 - 我知道,'all_follows'方法作用於'User'的實例,而不是'User'類。你需要一個特定的用戶來調用該方法。相應地更新了答案。 – rusty
該方法應該已經暴露給用戶。關注/取消關注按鈕正常工作。 –
這只是一個在'user'而不是'User'上調用它的問題嗎? – rusty