Skip to content
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

Advert #46

Merged
merged 2 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions app/controllers/advert_controller.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions app/helpers/advert_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module AdvertHelper
end
5 changes: 5 additions & 0 deletions app/models/advert.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions app/views/advert/index.html.erb
Original file line number Diff line number Diff line change
@@ -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 %>

12 changes: 12 additions & 0 deletions app/views/advert/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class="m-2">
<%= 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 %>


</div>
15 changes: 12 additions & 3 deletions app/views/home/_landing.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,26 @@
<% end %>
</div>


<% @advert.limit(1).each do |advert| %>
<div class="bg-white md:flex-col md:flex-row border-t-indigo-500 ">

<div class="flex flex-col md:items-end gap-5 hidden sm:flex ">
<div class="flex flex-col lg:w-[303px] md:w-[250px] text-white bg-black">
<%= image_tag 'featured1.png', class: "lg:max-w-[300px] md:max-w-[250px]"%>
<%= image_tag(advert.desk_image, class: "lg:max-w-[300px] md:max-w-[250px]") %>
<p class=" text-xs p-2">Featured</p>
<p class="text-sm p-4 font-semibold w-[90%]">Welcome to ST. Sebastian Park</p>
<p class="text-sm p-4 font-semibold w-[90%]">Welcome to ST. Sebastian Park Great</p>
</div>
</div>

<div class="sm:flex flex-col md:items-end m-[4%] md:hidden lg:hidden xl:hidden ">
<div class="flex flex-col w-[95%] h-[100px] text-white bg-black">
<%= image_tag(advert.mobile_image, class: "w-[100%] h-[100px] ") %>
<p class=" text-xs p-2">Featured Mobile</p>
<p class="text-sm p-4 font-semibold w-[90%]">Mobile</p>
</div>
</div>

</div>
<% end %>

</div>
2 changes: 1 addition & 1 deletion app/views/home/_schedule.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
10% Discount off On membership
</p>
<p class="mb-5 text-[#867A7A]">Medium</p>
<%= link_to "<button>Buy Now</button>".html_safe, shop_index_path, class: "bg-[#FAE115] flex justify-center text-black font-bold p-2 w-[80%] uppercase" %>
<%= link_to "<button>Buy Now</button>".html_safe, product_index_path, class: "bg-[#FAE115] flex justify-center text-black font-bold p-2 w-[80%] uppercase" %>
</div>
<%= image_tag "msealskit.png", alt: "Mseal Logo kit", class: "w-[50%]"%>

Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/_footer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
</div>
<div class="flex flex-col gap-2">
<h5 class="text-[#fae115]">
<%= link_to "SHOP", shop_index_path %>
<%= link_to "SHOP", product_index_path %>
</h5>
<!--
<ul>
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
get 'cart', to: 'cart#show'
post 'cart/add'
post 'cart/remove'
get 'shop/index'
root "home#index"
resources :home
devise_for :users
Expand All @@ -17,4 +16,5 @@
resources :fixture
resources :membership
resources :product
resources :advert
end
13 changes: 13 additions & 0 deletions db/migrate/20230711124426_create_adverts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateAdverts < ActiveRecord::Migration[7.0]
def change
create_table :adverts do |t|
t.string :type_of_advert
t.string :header_advert
t.string :mobile_image
t.string :desk_image
t.references :user, null: false, foreign_key: true

t.timestamps
end
end
end
14 changes: 13 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions test/controllers/advert_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class AdvertControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end
15 changes: 15 additions & 0 deletions test/fixtures/adverts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
type_of_advert: MyString
header_advert: MyString
mobile_image: MyString
desk_image: MyString
user_id: one

two:
type_of_advert: MyString
header_advert: MyString
mobile_image: MyString
desk_image: MyString
user_id: two
7 changes: 7 additions & 0 deletions test/models/advert_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class AdvertTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end