Unsubscribing Facebook admins and regular users from notifications What is the best way to DRY this code up?

class NotificationsController &lt; ApplicationController
  before_filter :load_user

  def unsubscribe
    if @facebook_admin &amp;&amp; @facebook_admin.auth_key == params[:auth_key]
      @facebook_admin.update_notification_settings(params[:type] =&gt; false)
    elsif @user &amp;&amp; @user.auth_key == params[:auth_key]
      @user.update_notification_settings(params[:type] =&gt; false)
    end
  end

  private

  def load_user
    if params[:type].present?
      if params[:facebook_admin_id].present?
        @facebook_admin = FacebookAdmin.find_by_id(params[:facebook_admin_id])
      elsif params[:user_id].present?
        @user = User.find_by_id(params[:user_id])
      end
    end
  end
end
Verbosity of a controller is typically a signal of dubious design. As I see it, you have two sensible options:


If User and FacebookAdmin are two very different user entities: they should be treated in two separate controllers.
If User and FacebookAdmin are very similar (i.e. FacebookAdmin inherits from User): they can share the same controller but use always @user as variable. This way the code will be simplified dramatically.


What you should not have is a controller full of conditional branches, that will be an unmaintainable mess (and awful to test).