Skip to content

Instantly share code, notes, and snippets.

@Dysp
Created May 4, 2016 18:57
Show Gist options
  • Save Dysp/ef6a5b3b871ee0333a4abd8c00d03032 to your computer and use it in GitHub Desktop.
Save Dysp/ef6a5b3b871ee0333a4abd8c00d03032 to your computer and use it in GitHub Desktop.
#The model section:
class Subject < ActiveRecord::Base
validates :name, :sex, :initial, :phone, :born_on, presence: true
validates :initial, :email, :phone, uniqueness: true, unless: :skip_unique_validation
validates :phone, format: { with: /\d/,
message: "allows only numbers" }
attr_accessor :skip_unique_validation
end
#The controller section:
def update
@subject.skip_unique_validation = true
@subject = Subject.find(params[:id])
if @subject.update(subject_params)
redirect_to @subject
else
render 'edit'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment