Skip to content
Snippets Groups Projects
Commit 08f0a300 authored by Arnaud Levy's avatar Arnaud Levy
Browse files

Better experiences #555

parent 9da1ef78
No related branches found
No related tags found
No related merge requests found
......@@ -32,9 +32,15 @@ class University::Person::Experience < ApplicationRecord
belongs_to :person
belongs_to :organization, class_name: "University::Organization"
validates_presence_of :organization
validates_presence_of :from_year
# TODO validateur de comparaison
# validates_numericality_of :to_year, { greater_than_or_equal_to: :from_year }, allow_nil: true
validate :to_year, :not_before_from_year
before_validation :create_organization_if_needed
scope :ordered, -> { order(from_year: :desc) }
scope :ordered, -> { order('university_person_experiences.to_year DESC NULLS FIRST, university_person_experiences.from_year') }
scope :recent, -> {
where.not(from_year: nil)
.order(from_year: :desc, created_at: :desc)
......@@ -52,6 +58,12 @@ class University::Person::Experience < ApplicationRecord
private
def not_before_from_year
if to_year.present? && to_year < from_year
errors.add :to_year
end
end
def create_organization_if_needed
if organization.nil? && organization_name.present?
self.organization_name = self.organization_name.strip
......
......@@ -6,7 +6,11 @@
<% else %>
<h1><%= yield :title %></h1>
<p class="header__additional_data">
<%= yield :header_right %>&nbsp;
<% if content_for(:header_right).present? %>
<%= yield :header_right %>
<% else %>
&nbsp;
<% end %>
</p>
<% end %>
</div>
......
<%= simple_form_for experience, url: experience.persisted? ? experience_path(experience) : experiences_path do |f| %>
<% if experience.errors.any? %>
<div id="error_explanation" class="text-danger">
<ul class="list-unstyled">
<% experience.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="row">
<div class="col-lg-6">
<%= f.input :description, as: :string %>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment