Advertisement
Guest User

Untitled

a guest
Aug 26th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. class User < ActiveRecord::Base
  2. # Include default devise modules. Others available are:
  3. # :confirmable, :lockable, :timeoutable and :omniauthable
  4. devise :database_authenticatable, :registerable,
  5. :recoverable, :rememberable, :trackable, :validatable
  6.  
  7. acts_as_followable
  8. acts_as_follower
  9. end
  10.  
  11. User.create(email: "ken@thefirehoseproject.com", password: "secretpassword123", password_confirmation: "secretpassword123")
  12. User.create(email: "marco@thefirehoseproject.com", password: "secretpassword123", password_confirmation: "secretpassword123")
  13.  
  14. ken = User.first
  15. marco = User.last
  16.  
  17. marco.follow!(ken)
  18.  
  19. ken.followers(User) # marco
  20. marco.followees(User) # ken
  21.  
  22.  
  23. # POST /users/:user_id/followers
  24. config/routes.rb
  25. resources :users, only: [] do
  26. resources :followers, only: [:create]
  27. end
  28.  
  29.  
  30. class FollowersController < ActionController::Base
  31.  
  32. def create
  33. other_user = User.find(params[:user_id])
  34. current_user # two different users we can access
  35. current_user.follow!(other_user)
  36. redirect_to root_path, notice: "You're following them now"
  37. end
  38.  
  39.  
  40.  
  41. def create
  42. other_user = User.find(params[:user_id])
  43. current_user.follow!(other_user)
  44. redirect_to root_path, notice: "You're following them now"
  45. end
  46. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement