diff --git a/app/controllers/advert_controller.rb b/app/controllers/advert_controller.rb new file mode 100644 index 000000000..7bdd8b0ad --- /dev/null +++ b/app/controllers/advert_controller.rb @@ -0,0 +1,41 @@ +class AdvertController < ApplicationController + before_action :authenticate_user!, except: %i[index show] + + def index + @adverts = Advert.all + end + + def show + @advert = Advert.find(params[:id]) + end + + def new + @advert = Advert.new + end + + def create + @advert = Advert.new(advert_params) + @advert.user_id = current_user.id + respond_to do |format| + if @advert.save + format.html { redirect_to advert_url(@advert), notice: 'Advert was successfully created.' } + else + format.html { redirect_to advert_index_url, notice: 'Failure' } + end + end + end + + def destroy + @advert = Advert.find(params[:id]) + @advert.delete + respond_to do |format| + format.html { redirect_to advert_index_path, notice: 'Advert was successfully deleted.' } + end + end + + private + + def advert_params + params.permit(:type_of_advert, :header_advert, :mobile_image, :desk_image, :user_id) + end +end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index c70a28c58..e607318f2 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -3,5 +3,6 @@ class HomeController < ApplicationController def index @news = News.all.order('created_at DESC') + @advert = Advert.all.order('created_at DESC') end end diff --git a/app/helpers/advert_helper.rb b/app/helpers/advert_helper.rb new file mode 100644 index 000000000..50b2f6037 --- /dev/null +++ b/app/helpers/advert_helper.rb @@ -0,0 +1,2 @@ +module AdvertHelper +end diff --git a/app/models/advert.rb b/app/models/advert.rb new file mode 100644 index 000000000..cf32605f3 --- /dev/null +++ b/app/models/advert.rb @@ -0,0 +1,5 @@ +class Advert < ApplicationRecord + belongs_to :user, class_name: 'User', optional: true + has_one_attached :mobile_image + has_one_attached :desk_image +end diff --git a/app/models/user.rb b/app/models/user.rb index 2dc71a758..b46e24e62 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -15,4 +15,5 @@ def set_default_role has_many :news, foreign_key: :user_id, class_name: 'News', dependent: :destroy has_many :clubs, foreign_key: :user_id, class_name: 'Club', dependent: :destroy + has_many :adverts, foreign_key: :user_id, class_name: 'Advert', dependent: :destroy end diff --git a/app/views/advert/index.html.erb b/app/views/advert/index.html.erb new file mode 100644 index 000000000..e5f454149 --- /dev/null +++ b/app/views/advert/index.html.erb @@ -0,0 +1,8 @@ +<% @adverts.limit(1).each do |advert| %> + + <%= image_tag(advert.mobile_image, class: "hidden sm:flex") %> + <%= image_tag(advert.desk_image, class: "lg:flex md:flex lg:h-40 lg:w-60 h-28 md:h-40 hidden") %> + + +<% end %> + diff --git a/app/views/advert/new.html.erb b/app/views/advert/new.html.erb new file mode 100644 index 000000000..53d3d7eb6 --- /dev/null +++ b/app/views/advert/new.html.erb @@ -0,0 +1,12 @@ +
+ <%= form_with model: @adverts, url: advert_index_url, method: :post, data: { turbo: false }, local: true do |f| %> + <%= f.file_field :mobile_image %> + <%= f.file_field :desk_image %> + + <%= f.text_area :type_of_advert %> + <%= f.text_area :header_advert %> + <%= f.submit %> + <% end %> + + +
diff --git a/app/views/home/_landing.html.erb b/app/views/home/_landing.html.erb index f19fac63c..98a302b31 100644 --- a/app/views/home/_landing.html.erb +++ b/app/views/home/_landing.html.erb @@ -57,17 +57,26 @@ <% end %> - + <% @advert.limit(1).each do |advert| %>
+ +
+
+ <%= image_tag(advert.mobile_image, class: "w-[100%] h-[100px] ") %> +

Featured Mobile

+

Mobile

+ <% end %> \ No newline at end of file diff --git a/app/views/home/_schedule.html.erb b/app/views/home/_schedule.html.erb index f3c727665..1fe340665 100644 --- a/app/views/home/_schedule.html.erb +++ b/app/views/home/_schedule.html.erb @@ -56,7 +56,7 @@ 10% Discount off On membership

Medium

- <%= link_to "".html_safe, shop_index_path, class: "bg-[#FAE115] flex justify-center text-black font-bold p-2 w-[80%] uppercase" %> + <%= link_to "".html_safe, product_index_path, class: "bg-[#FAE115] flex justify-center text-black font-bold p-2 w-[80%] uppercase" %> <%= image_tag "msealskit.png", alt: "Mseal Logo kit", class: "w-[50%]"%> diff --git a/app/views/layouts/_footer.html.erb b/app/views/layouts/_footer.html.erb index b8d506fd5..f7b677d9f 100644 --- a/app/views/layouts/_footer.html.erb +++ b/app/views/layouts/_footer.html.erb @@ -54,7 +54,7 @@
- <%= link_to "SHOP", shop_index_path %> + <%= link_to "SHOP", product_index_path %>