title: Rails check if params exist in the controller
body: <p>I have a <code>factor</code> controller which takes factor values for two different types of factors</p>
  
  <ol>
  <li>Primary Factor</li>
  <li>Secondary Factor</li>
  </ol>
  
  <p>And I pass them as params as follows:</p>
  
  <pre><code>class FactorController &lt; AdminController
  
    def create
      if primary_factor_params                              ## LINE 5
        do something
      elsif secondary_factor_params
        do something else
      end
    end
  
    def primary_factor_params
      params.require(:primary).permit(:user_id,            ## LINE 70
                                             :primary_factors)
    end
  
    def secondary_factor_params
      params.require(:secondary).permit(:user_id,
                                          :secondary_factors)
    end
  end
  </code></pre>
  
  <p>But in the above whenever I try to pass a <code>secondary_factor</code> I get the following error:</p>
  
  <pre><code>ActionController::ParameterMissing (param is missing or the value is empty: primary):
    app/controllers/factors_controller.rb:70:in `primary_factor_params'  app/controllers/api/v1/admin/factors_controller.rb:5:in `create'
  </code></pre>
  
  <p>So to me it seems that this error is coming up because I didn't have any values for <code>primary_factor_params</code> in this condition and that's way it throws the error because of the first if condition.</p>
  
  <p>I've tried:</p>
  
  <pre><code>primary_factor_params.exists?
  primary_factor_params.has_key?(:primary_factors)
  ....
  </code></pre>
  
  <p>But all of them throw the same error since <code>primary_factor_params</code> doesn't exist. Is there a way to test this without throwing an error for missing params?</p>