title: how to skip model validation for particular function in rails?
body: <p>I want to skip some model validation for controller functions. I am doing like this</p>
  
  <p>Model :</p>
  
  <pre><code>attr_accessible :skip_method_2
  validates :name,  presence: true, length: { maximum: 50 }, :unless =&gt; :skip_method_2
  VALID_PHONE_REGEX = /\(?([0-9]{3})\)?([ .-]?)([0-9]{3})\2([0-9]{4})/
  validates :phoneno, presence: true,uniqueness: { case_sensitive: false, :scope =&gt; :user_id}, format: { with: VALID_PHONE_REGEX }, :unless =&gt; :skip_method_2
  </code></pre>
  
  <p>Controller :</p>
  
  <pre><code>def contacts_callback
   @contacts = request.env['omnicontacts.contacts']   
   @contacts.each do |contact|
     next if current_user.contacts.exists?(:email =&gt; "#{contact[:email]}")
     contact1 = current_user.contacts.new(:skip_method_2 =&gt; true)
     contact1.name = contact[:name] 
     contact1.email = contact[:email]
     contact1.group = "Others"
     contact1.save
   end
    redirect_to "/contact"
  end
  </code></pre>
  
  <p>I dont want to save it by :validation => false. I want to skip name and phoneno validation for contacts_callback function. But it is not working.</p>
  
  <p>It gives error in controller -
  undefined local variable or method `skip_method_2' for contacts_callback. I already mentioned attr_accessible in my model</p>