Created
May 4, 2016 18:57
-
-
Save Dysp/ef6a5b3b871ee0333a4abd8c00d03032 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
#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