Skip to content

Commit

Permalink
Update include:
Browse files Browse the repository at this point in the history
  - Add a section that lists the currently available learning materials for people who do not want to view the cards listed above
  - Add validations in the learning materials model for the title, description and link
  - Refactor error message localization in LearningMaterial model to improve code maintainability
  • Loading branch information
Nemwel-Boniface committed Apr 18, 2024
1 parent bc13a7f commit f4e6447
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/models/learning_material.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ class LearningMaterial < ApplicationRecord

# Enum
enum tag: { beginners: 0, intermediates: 1, experts: 2 }

# Validations
validates :tag, :learning_material_title, :learning_material_description, :learning_material_link, presence: true
validates :learning_material_link,
format: { with: URI::DEFAULT_PARSER.make_regexp(%w[http https]), message: :invalid_url }
end
14 changes: 14 additions & 0 deletions app/views/learning_materials/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,18 @@
</div>
<% end %>
</div>
<div class="pb-20 pt-20">
<h2 style="color: #D0021B;" class="text-2xl sm:text-3xl md:text-4xl lg:text-5xl xl:text-6xl font-bold text-left">If you may not want the view above, here is a list of the same details shown above.</h2>
</div>
<ol type="1" start="1" class="max-w-md space-y-1 text-gray-500 dark:text-gray-400" style="list-style-type: decimal; padding-left: 20px;">
<% @learningmaterials.each do |learningmaterial| %>
<li class="py-2">
<span class="py-1 text-sm sm:text-base md:text-lg lg:text-xl xl:text-2xl font-regular mr-1">
<%= link_to learningmaterial.learning_material_title, learningmaterial.learning_material_link, class: "learningmaterialslink ml-1", target: "_blank", style: "color: #D0021B;" %> <span> - <%= learningmaterial.learning_material_description %> </span>
</span>
</li>
<% end %>
</ol>
</section>
4 changes: 4 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ en:
destroy:
success: 'Project was successfully destroyed.'

errors:
messages:
invalid_url: "must be a valid URL"


0 comments on commit f4e6447

Please sign in to comment.