Skip to content

Instantly share code, notes, and snippets.

@Dysp
Last active May 6, 2016 11:23
Show Gist options
  • Save Dysp/bda88f62941a4db5c6febba4353a2e7a to your computer and use it in GitHub Desktop.
Save Dysp/bda88f62941a4db5c6febba4353a2e7a to your computer and use it in GitHub Desktop.
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