显示我选择关注的所有用户的推文

时间:2014-10-26 06:33:03

标签: ruby-on-rails twitter nomethoderror find-all-references

实际上,我只是想为用户创建一个个人资料页面(类似于你在实际的Twitter中所拥有的),我希望这个页面显示我所选择关注的所有用户的推文。 / p>

我想做的是:

def profile
    if current_user
        @tweet = Tweet.new
        all_ids = current_user.followeds.map(&:id).push(current_user.id)
        @tweets = Tweet.find_all_by_user_id(all_ids)
    else
        redirect_to root_path
    end
end

'个人资料操作'在UsersController中。


我的routes.rb文件:

devise_for :users, :controllers => { :registrations => "registrations" }
resources :users, only: [:show]
resources :tweets
resources :relationships, only: [:create, :destroy]
root to: "home#index"   
get '/profile', to: 'users#profile', as: 'profile'

现在,当我访问localhost:3000 / profile时,它说: -

UsersController #profile中的NoMethodError

未定义的方法`find_all_by_user_id'对于#

我该怎么做才能解决这个问题? 如果您需要更多代码,请告诉我们。提前谢谢。

1 个答案:

答案 0 :(得分:0)

find_all_by样式动态方法已在Rails 4

中弃用

使用where

@tweets = Tweet.where(user_id: all_ids)