title: Use string variable as field name in where condition in rails 4
body: <p>I've a method  in the controller which checks if a field's value already exist in database.In my case I've to check for the multiple fields such as username, email, and URL via AJAX.</p>
  
  <p>So I wrote the function below</p>
  
  <pre><code>  def check_field_already_exist?(field, params )
  
      merchant_url = MerchantUrl.where(field: filter_params[field.to_sym]).first
  
       # here params[:id] is available only while editing the MerchantUrl
       is_available = if (params[:id] &amp;&amp; merchant_url)
                   merchant_url.id == params[:id]
                 else
                   merchant_url.blank?
                 end
    end
  </code></pre>
  
  <p>and invoke this method as </p>
  
  <pre><code>  def is_name_available
      render json: check_field_already_exist?('username', params)
    end
  
    def is_url_available
      render json: check_field_already_exist?('url', params)
    end
  
    def is_email_available
      render json: check_field_already_exist?('email', params)
    end
  </code></pre>
  
  <p>but on execution it throws the error </p>
  
  <p>Mysql2::Error: <strong>Unknown column 'merchant_urls.field'</strong> in 'where clause': SELECT <code>merchant_urls</code>.* FROM <code>merchant_urls</code> WHERE <code>merchant_urls</code>.<code>field</code> = '<a href="http://localhost:3000" rel="nofollow">http://localhost:3000</a>'</p>
  
  <p>So, Is there any method to use string variable as field name?
  Thank you.</p>