Actually, I just want to create a profile page for a user(similar to what you have in actual Twitter), and I want this page to display the tweets from all the users I've chosen to follow.
What I'm trying to do is:
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
'Profile action' is in UsersController.
My routes.rb file:
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'
Now, when I visit localhost:3000/profile, it says:-
NoMethodError in UsersController#profile
undefined method `find_all_by_user_id' for #
What should I do to resolve this issue? Let me know if you need some more code. Thank you in advance.
find_all_by
style dynamic methods are deprecated in Rails 4
Use where
,
@tweets = Tweet.where(user_id: all_ids)