Last active
May 6, 2016 11:23
-
-
Save Dysp/bda88f62941a4db5c6febba4353a2e7a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Model: | |
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 | |
Controller: | |
def update | |
@subject = Subject.find(params[:id]) | |
@subject.skip_unique_validation = true | |
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