Skip to content
Open
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
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby "3.1.2"

gem 'bootstrap', '~> 5.2.1'
gem 'devise'
gem 'importmap-rails'
gem "rails", "~> 7.0.4"
Expand Down
23 changes: 4 additions & 19 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,7 @@ GEM
tzinfo (~> 2.0)
addressable (2.8.1)
public_suffix (>= 2.0.2, < 6.0)
autoprefixer-rails (10.4.7.0)
execjs (~> 2)
bcrypt (3.1.18)
bootstrap (5.2.1)
autoprefixer-rails (>= 9.1.0)
popper_js (>= 2.11.6, < 3)
sassc-rails (>= 2.0.0)
builder (3.2.4)
capybara (3.37.1)
addressable
Expand All @@ -98,8 +92,6 @@ GEM
warden (~> 1.2.3)
diff-lcs (1.5.0)
erubi (1.11.0)
execjs (2.8.1)
ffi (1.15.5)
globalid (1.0.0)
activesupport (>= 5.0)
i18n (1.12.0)
Expand Down Expand Up @@ -131,8 +123,9 @@ GEM
nio4r (2.5.8)
nokogiri (1.13.8-arm64-darwin)
racc (~> 1.4)
nokogiri (1.13.8-x86_64-linux)
racc (~> 1.4)
orm_adapter (0.5.0)
popper_js (2.11.6)
public_suffix (5.0.0)
puma (5.6.5)
nio4r (~> 2.0)
Expand Down Expand Up @@ -190,14 +183,6 @@ GEM
rspec-mocks (~> 3.11)
rspec-support (~> 3.11)
rspec-support (3.11.1)
sassc (2.4.0)
ffi (~> 1.9)
sassc-rails (2.1.2)
railties (>= 4.0.0)
sassc (>= 2.0)
sprockets (> 3.0)
sprockets-rails
tilt
sprockets (4.1.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
Expand All @@ -206,8 +191,8 @@ GEM
activesupport (>= 5.2)
sprockets (>= 3.0.0)
sqlite3 (1.5.2-arm64-darwin)
sqlite3 (1.5.2-x86_64-linux)
thor (1.2.1)
tilt (2.0.11)
timeout (0.3.0)
tzinfo (2.0.5)
concurrent-ruby (~> 1.0)
Expand All @@ -222,9 +207,9 @@ GEM

PLATFORMS
arm64-darwin-21
x86_64-linux

DEPENDENCIES
bootstrap (~> 5.2.1)
capybara
debug
devise
Expand Down
2 changes: 0 additions & 2 deletions app/assets/stylesheets/application.scss

This file was deleted.

6 changes: 0 additions & 6 deletions app/assets/stylesheets/theme.css

This file was deleted.

2 changes: 0 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
class ApplicationController < ActionController::Base


end
21 changes: 0 additions & 21 deletions app/controllers/product_categories_controller.rb

This file was deleted.

51 changes: 6 additions & 45 deletions app/controllers/products_controller.rb
Original file line number Diff line number Diff line change
@@ -1,61 +1,22 @@
class ProductsController < ApplicationController
before_action :set_product, only: %i[ show edit update destroy ]

# GET /products
def index
@products = Product.all
@product = Product.new
@product_category = ProductCategory.new
@product_categories = ProductCategory.all
end

# GET /products/1
def show
end

# GET /products/new
def new
@product = Product.new
@product_categories = ProductCategory.all
end

# GET /products/1/edit
def edit
end

# POST /products
def create
@product_categories = ProductCategory.all
product_params = params.require(:product).permit(:name, :price, :product_category_id)
@product = Product.new(product_params)

if @product.save
redirect_to @product, notice: "Product was successfully created."
redirect_to root_path, notice: 'Produto cadastrado com sucesso.'
else
render :new, status: :unprocessable_entity
flash.now[:notice] = 'Não foi possível cadastrar o produto.'
render 'new'
end
end

# PATCH/PUT /products/1
def update
if @product.update(product_params)
redirect_to @product, notice: "Product was successfully updated."
else
render :edit, status: :unprocessable_entity
end
end

# DELETE /products/1
def destroy
@product.destroy
redirect_to products_url, notice: "Product was successfully destroyed."
end

private
# Use callbacks to share common setup or constraints between actions.
def set_product
@product = Product.find(params[:id])
end

# Only allow a list of trusted parameters through.
def product_params
params.require(:product).permit(:name, :price, :product_category_id)
end
end
9 changes: 0 additions & 9 deletions app/controllers/welcome_controller.rb

This file was deleted.

1 change: 1 addition & 0 deletions app/models/product_category.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class ProductCategory < ApplicationRecord
validates :name, presence: true
has_many :products
end
55 changes: 10 additions & 45 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -1,56 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<title>SistemaFrete</title>
<title>ProductsApp</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>

<%= stylesheet_link_tag "application" %>
<%= javascript_importmap_tags %>
</head>

<body>
<nav class="navbar navbar-expand-lg bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown
</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link disabled">Disabled</a>
</li>
</ul>
<%= form_with(url: root_path, class: 'd-flex') do |f| %>
<%= f.text_field :busca, class: 'form-control me-2' %>
<%= f.submit 'Buscar', class: 'btn btn-outline-success' %>
<% end %>
</div>
<header>
<h1>Produtos</h1>
</header>
<main>
<div>
<%= alert %>
<%= notice %>
</div>
</nav>

<div class="container">
<%= notice %>
<%= yield %>
</div>
<%= yield %>
</main>
</body>
</html>
1 change: 0 additions & 1 deletion app/views/product_categories/_product_category.html.erb

This file was deleted.

27 changes: 0 additions & 27 deletions app/views/products/_form.html.erb

This file was deleted.

12 changes: 0 additions & 12 deletions app/views/products/_product.html.erb

This file was deleted.

10 changes: 0 additions & 10 deletions app/views/products/edit.html.erb

This file was deleted.

56 changes: 10 additions & 46 deletions app/views/products/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,50 +1,14 @@
<p style="color: green"><%= notice %></p>

<h1>Products</h1>
<div id="products">
<% @products.each do |product| %>
<%= render product %>
<p>
<%= link_to "Show this product", product %>
</p>
<% end %>
</div>
<hr/>
<h2>Nova Categoria de Produto</h2>
<%= form_with(model: @product_category) do |f| %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.submit %>
<% end %>
<hr/>



<h2>Novo Produto</h2>
<%= form_with(model: @product) do |form| %>
<div>
<%= form.label :name, style: "display: block" %>
<%= form.text_field :name %>
</div>

<h2>Produtos</h2>
<div>
<%= link_to 'Cadastrar produto', new_product_path %>
<% @products.each do |p| %>
<div>
<%= form.label :price, style: "display: block" %>
<%= form.text_field :price %>
</div>

<div>
<%= form.label :condition_new, 'Produto Novo' %>
<%= form.radio_button :condition, :new %>

<%= form.label :condition_used, 'Produto Usado' %>
<%= form.radio_button :condition, :used %>
</div>

<div>
<%= form.submit %>
</div>
Produto: <%= p.name %> - <%= p.product_category.name %> - R$ <%= p.price %>
</div>
<% end %>
</div>


choose 'Produto Usado'
<% if @products.empty? %>
<p>Não existem produtos cadastrados </p>
<% end %>

Loading