-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make learning materials page CRUD using the Rails Admin gem #87
base: main
Are you sure you want to change the base?
Changes from 9 commits
e8acb37
8717427
a6d167f
5a18fcc
f0da3d4
78753a1
a2ddd4e
bc13a7f
f4e6447
a5b1b1d
a944f54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--require spec_helper |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,14 @@ | ||||||
# frozen_string_literal: true | ||||||
Nemwel-Boniface marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
class LearningMaterialsController < ApplicationController | ||||||
skip_before_action :authenticate_user!, only: %i[index] | ||||||
|
||||||
def index | ||||||
@learningmaterials = LearningMaterial.all | ||||||
Nemwel-Boniface marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
@learningmaterials_with_thumbnails = @learningmaterials.select do |learningmaterial| | ||||||
learningmaterial.thumbnail.attached? | ||||||
end | ||||||
@random_learningmaterials = @learningmaterials_with_thumbnails.sample(2) | ||||||
@learningmaterials_with_or_without_thumbnails = @learningmaterials - @random_learningmaterials | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
maybe this makes more sense? 🤷♂️ naming things is hard 😅 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for this suggestion and yes naming things is really hard because there is never a "one right/ true way" to name things. The reason why it is named as "with or without thumbnails" is because it is supposed to hold all other Learning materials regardless of whether that specific learning material has an attached thumbnail or not. If this is renamed to your suggestion I am afraid it will lead to slight confusion later. What do you think @denissellu ? 🤔 |
||||||
end | ||||||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
module LearningMaterialsHelper | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
class LearningMaterial < ApplicationRecord | ||
# Associations | ||
belongs_to :user | ||
has_one_attached :thumbnail | ||
|
||
# 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<% content_for(:title,"Learning Materials") %> | ||
<% content_for(:description,"A list of ruby and ruby on rails learning resources compiled by the ARC community") %> | ||
|
||
<section class="max-w-screen-xl mx-auto p-5 sm:p-10 md:p-16 pt-20"> | ||
<div class="pb-15"> | ||
<h1 style="color: #D0021B;" class="text-4xl sm:text-5xl md:text-6xl lg:text-7xl xl:text-8xl font-bold text-left">Featured Materials</h1> | ||
</div> | ||
|
||
<div class="grid grid-cols-1 md:grid-cols-2 gap-10 pt-7"> | ||
<% if @learningmaterials.empty? %> | ||
<h2>There are no created learning materials yet</h2> | ||
<% else %> | ||
<% # Display the selected random records with thumbnails %> | ||
<% @random_learningmaterials.each do |learningmaterial| %> | ||
<div class="rounded overflow-hidden shadow-lg p-4 border-b-2 border-dashed border-black-600"> | ||
<a href="#"></a> | ||
<div class="relative"> | ||
<div class="py-4" style="height: 300px;"> | ||
<img src="<%= url_for(learningmaterial.thumbnail) %>" class="w-full h-full object-cover rounded-lg"> | ||
</div> | ||
<div class="text-sm absolute top-0 right-0 bg-indigo-600 px-4 text-white rounded-full h-16 w-16 flex items-center justify-center mt-3 mr-3 hover:bg-white hover:text-indigo-600 transition duration-500 ease-in-out"> | ||
<span class="font-bold"><%= learningmaterial.created_at.strftime("%b %d") %></span> | ||
</div> | ||
</div> | ||
<div class="px-6 py-4 flex justify-between items-center"> | ||
<p class="font-semibold text-lg sm:text-xl md:text-2xl lg:text-3xl xl:text-4xl inline-block hover:text-indigo-600 transition duration-500 ease-in-out"><%= learningmaterial.learning_material_title %></p> | ||
<p class="text-gray-500 text-sm sm:text-base md:text-lg lg:text-xl xl:text-2xl"><%= learningmaterial.tag %></p> | ||
</div> | ||
<div class="px-6 py-4 flex justify-between items-center"> | ||
<p class="py-2 text-base sm:text-lg md:text-xl lg:text-2xl xl:text-3xl font-normal"><%= learningmaterial.learning_material_description %></p> | ||
</div> | ||
<div class="px-6 py-4 flex flex-row items-center"> | ||
<span class="py-1 text-sm sm:text-base md:text-lg lg:text-xl xl:text-2xl font-regular mr-1"> | ||
<%= link_to "READ MORE HERE", learningmaterial.learning_material_link, class: "learningmaterialslink ml-1", target: "_blank", style: "color: #D0021B;" %> | ||
</span> | ||
</div> | ||
</div> | ||
<% end %> | ||
<% 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">Other Resources</h2> | ||
</div> | ||
|
||
<% # Display the remaining records regardless of whether it has thumbnail or not %> | ||
<div class="grid grid-cols-1 md:grid-cols-3 gap-10 max-w-screen-xl mx-auto p-5 sm:p-10 md:p-16"> | ||
<% @learningmaterials_with_or_without_thumbnails.each do |learningmaterial| %> | ||
<div class="rounded overflow-hidden shadow-lg p-4 border-b border-dotted border-gray-400"> | ||
<a href="#"></a> | ||
<div class="relative"> | ||
<% if learningmaterial.thumbnail.attached? %> | ||
<div class="py-4" style="height: 300px;"> | ||
<img src="<%= url_for(learningmaterial.thumbnail) %>" class="w-full h-full object-cover rounded-lg"> | ||
</div> | ||
<% else %> | ||
<div class="py-4" style="height: 300px;"> | ||
<img src="/assets/learningmaterialsthumbnail.jpeg" class="w-full h-full object-cover rounded-lg"> | ||
</div> | ||
<% end %> | ||
<div class="text-sm absolute top-0 right-0 bg-indigo-600 px-4 text-white rounded-full h-16 w-16 flex items-center justify-center mt-3 mr-3 hover:bg-white hover:text-indigo-600 transition duration-500 ease-in-out"> | ||
<span class="font-bold"><%= learningmaterial.created_at.strftime("%b %d") %></span> | ||
</div> | ||
</div> | ||
<div class="px-6 py-4 flex justify-between items-center"> | ||
<p class="font-semibold text-lg sm:text-xl md:text-2xl lg:text-3xl xl:text-4xl inline-block hover:text-indigo-600 transition duration-500 ease-in-out"><%= learningmaterial.learning_material_title %></p> | ||
<p class="text-gray-500 text-sm sm:text-base md:text-lg lg:text-xl xl:text-2xl"><%= learningmaterial.tag %></p> | ||
</div> | ||
<div class="px-6 py-4 flex justify-between items-center"> | ||
<p class="py-2 text-base sm:text-lg md:text-xl lg:text-2xl xl:text-3xl font-normal"><%= learningmaterial.learning_material_description %></p> | ||
</div> | ||
<div class="px-6 py-4 flex flex-row items-center"> | ||
<span class="py-1 text-sm sm:text-base md:text-lg lg:text-xl xl:text-2xl font-regular mr-1"> | ||
<%= link_to "READ MORE HERE", learningmaterial.learning_material_link, class: "learningmaterialslink ml-1", target: "_blank", style: "color: #D0021B;" %> | ||
</span> | ||
</div> | ||
</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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i myself prefer Rspec too, if we are going with Rspec, then we need to remove minitest, or make it clear which one we should be using on the project! @JudahSan @banta should we keep Rspec over Minitest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw i'm aware that replacing minitest with rspec will also mean updating the github action to actually run the tests and move any minitest already written
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking forward to your opinions on this @banta and @JudahSan