daily pastebin goal
17%
SHARE
TWEET

Untitled

a guest Oct 12th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Proposed benefits:
  2. # * more verbose, but you can see more clearly all the "stuff" your method is using
  3. # * easier to re-use methods, since they're not coupled to instance var names
  4.  
  5. class UsersController < ApplicationController
  6.   def update
  7.     load_user
  8.     check_if_user_now_active
  9.   end
  10.  
  11.   private
  12.   def load_user
  13.     @user = User.find(params[:user_id])
  14.   end
  15.  
  16.   def check_if_user_now_active
  17.     flash.add(:info, "active") if @user.active?
  18.   end
  19. end
  20.  
  21. vs
  22.  
  23. class UsersController < ApplicationController
  24.   def update
  25.     @user = load_user
  26.     check_if_user_now_active(@user, flash)
  27.   end
  28.  
  29.   private
  30.   def load_user(params)
  31.     User.find(params[:user_id])
  32.   end
  33.  
  34.   def check_if_user_now_active(user, flash)
  35.     flash.add(:info, "active") if user.active?
  36.   end
  37. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top