Last active
December 2, 2016 09:47
-
-
Save luckyruby/30d6136ff05da4da6cb83c8b2c5445b6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
- if object.errors.any? | |
.alert.alert-danger.fade.in | |
%a.close{"data-dismiss" => 'alert'} × | |
%ul | |
- object.errors.each do |attr, msg| | |
- if msg.first == "^" | |
= content_tag :li, msg[1..-1] if msg.is_a? String | |
- else | |
= content_tag :li, "#{object.class.human_attribute_name(attr)} #{msg}" if msg.is_a? String |
This file contains hidden or 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
class CourseRegistration < ActiveRecord::Base | |
belongs_to :course | |
belongs_to :user | |
validates :course, :user, :first_name, :last_name, :age, presence: true | |
validates :last_name, | |
uniqueness: { | |
scope: [:first_name, :course_id, :user_id], | |
case_sensitive: false, | |
message: "^This student has already been registered." | |
} | |
validates :age, | |
numericality: { | |
only_integer: true, greater_than: 5 | |
} | |
def name | |
"#{first_name} #{last_name}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment