Skip to content

Instantly share code, notes, and snippets.

@luckyruby
Last active December 2, 2016 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luckyruby/30d6136ff05da4da6cb83c8b2c5445b6 to your computer and use it in GitHub Desktop.
Save luckyruby/30d6136ff05da4da6cb83c8b2c5445b6 to your computer and use it in GitHub Desktop.
- 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
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