-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from Lifeline-Solutions/advert
Advert
- Loading branch information
Showing
16 changed files
with
140 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module AdvertHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |