Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User < ActiveRecord::Base
- # Include default devise modules. Others available are:
- # :confirmable, :lockable, :timeoutable and :omniauthable
- devise :database_authenticatable, :registerable,
- :recoverable, :rememberable, :trackable, :validatable
- acts_as_followable
- acts_as_follower
- end
- User.create(email: "ken@thefirehoseproject.com", password: "secretpassword123", password_confirmation: "secretpassword123")
- User.create(email: "marco@thefirehoseproject.com", password: "secretpassword123", password_confirmation: "secretpassword123")
- ken = User.first
- marco = User.last
- marco.follow!(ken)
- ken.followers(User) # marco
- marco.followees(User) # ken
- # POST /users/:user_id/followers
- config/routes.rb
- resources :users, only: [] do
- resources :followers, only: [:create]
- end
- class FollowersController < ActionController::Base
- def create
- other_user = User.find(params[:user_id])
- current_user # two different users we can access
- current_user.follow!(other_user)
- redirect_to root_path, notice: "You're following them now"
- end
- def create
- other_user = User.find(params[:user_id])
- current_user.follow!(other_user)
- redirect_to root_path, notice: "You're following them now"
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement