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: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ gem "sprockets-rails"
gem "sqlite3", "~> 1.4"
gem "puma", "~> 5.0"
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
gem 'rails-i18n'

group :development, :test do
gem "capybara"
Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ 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)
Expand Down Expand Up @@ -159,6 +161,9 @@ GEM
nokogiri (>= 1.6)
rails-html-sanitizer (1.4.3)
loofah (~> 2.3)
rails-i18n (7.0.5)
i18n (>= 0.7, < 2)
railties (>= 6.0.0, < 8)
railties (7.0.4)
actionpack (= 7.0.4)
activesupport (= 7.0.4)
Expand Down Expand Up @@ -206,6 +211,7 @@ 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)
Expand All @@ -222,6 +228,7 @@ GEM

PLATFORMS
arm64-darwin-21
x86_64-linux

DEPENDENCIES
bootstrap (~> 5.2.1)
Expand All @@ -231,6 +238,7 @@ DEPENDENCIES
importmap-rails
puma (~> 5.0)
rails (~> 7.0.4)
rails-i18n
rspec-rails
sprockets-rails
sqlite3 (~> 1.4)
Expand Down
21 changes: 0 additions & 21 deletions app/controllers/product_categories_controller.rb

This file was deleted.

86 changes: 25 additions & 61 deletions app/controllers/products_controller.rb
Original file line number Diff line number Diff line change
@@ -1,61 +1,25 @@
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
end

# GET /products/1/edit
def edit
end

# POST /products
def create
@product = Product.new(product_params)

if @product.save
redirect_to @product, notice: "Product was successfully created."
else
render :new, status: :unprocessable_entity
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
class ProductsController < ApplicationController
def index
@products = Product.all
end

def new
@product = Product.new
@product_categories = ProductCategory.all
end

def create
product_params = params.require(:product).permit(:name, :price, :product_category_id)
@product = Product.new(product_params)

if @product.save
redirect_to root_url, notice: 'Produto cadastrado com sucesso'

else
@product_categories = ProductCategory.all

flash.now[:notice] = 'Produto não cadastrado'
render 'new'
end
end
end
9 changes: 0 additions & 9 deletions app/controllers/welcome_controller.rb

This file was deleted.

2 changes: 2 additions & 0 deletions app/models/product.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class Product < ApplicationRecord
belongs_to :product_category, optional: true

validates :name, :price, presence: true
end


Expand Down
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.

63 changes: 13 additions & 50 deletions app/views/products/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,50 +1,13 @@
<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>

<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>
<% end %>


choose 'Produto Usado'

<h1>Fretes</h1>

<%= link_to 'Cadastrar Produto', new_product_path %>

<% @products.each do |product| %>
<dl class="card" style="width: 18rem;">
<h4><%= product.name %></h4>
<dt>Preço: </dt>
<dd><%= number_to_currency(product.price) %></dd>
<dt>Categoria: </dt>
<dd><%= product.product_category.name %></dd>
</dl>
<% end%>
31 changes: 22 additions & 9 deletions app/views/products/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
<h1>New product</h1>

<%= render "form", product: @product %>

<br>

<div>
<%= link_to "Back to products", products_path %>
</div>
<% if @product.errors.any? %>
<div class="my-3 alert alert-danger">
<ul>
<% @product.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

<%= form_with(model: @product) do |f| %>
<%= f.label :name, 'Nome' %>
<%= f.text_field :name %>

<%= f.label :price, 'Preço' %>
<%= f.number_field :price, step: 0.01 %>

<%= f.label :product_category_id, 'Categoria' %>
<%= f.collection_select :product_category_id, @product_categories, :id, :name %>

<%= f.submit 'Criar' %>
<% end %>
12 changes: 0 additions & 12 deletions app/views/products/show.html.erb

This file was deleted.

42 changes: 0 additions & 42 deletions app/views/welcome/index.html.erb

This file was deleted.

5 changes: 5 additions & 0 deletions config/initializers/locale.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Permitted locales available for the application
I18n.available_locales = [:en, :'pt-BR']

# Set default locale to something other than :en
I18n.default_locale = :'pt-BR'
Loading