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
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby-3.1.2
ruby-3.0.0
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby "3.1.2"
ruby "3.0.0"

gem 'bootstrap', '~> 5.2.1'
gem 'devise'
Expand Down
6 changes: 5 additions & 1 deletion 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 @@ -206,6 +208,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 +225,7 @@ GEM

PLATFORMS
arm64-darwin-21
x86_64-linux

DEPENDENCIES
bootstrap (~> 5.2.1)
Expand All @@ -237,7 +241,7 @@ DEPENDENCIES
tzinfo-data

RUBY VERSION
ruby 3.1.2p20
ruby 3.0.0p0

BUNDLED WITH
2.3.14
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Sistema de Frete




Este é uma app com fins de estudos em turmas da Campus Code.


5 changes: 5 additions & 0 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class HomeController < ApplicationController
def index
@products = Product.all
end
end
21 changes: 0 additions & 21 deletions app/controllers/product_categories_controller.rb

This file was deleted.

56 changes: 5 additions & 51 deletions app/controllers/products_controller.rb
Original file line number Diff line number Diff line change
@@ -1,61 +1,15 @@
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_categories = ProductCategory.all
@product = Product.new
end

# GET /products/1/edit
def edit
end

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

if @product.save
redirect_to @product, notice: "Product was successfully created."
else
render :new, status: :unprocessable_entity
if @product.save
redirect_to root_path
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
end
9 changes: 0 additions & 9 deletions app/controllers/welcome_controller.rb

This file was deleted.

10 changes: 10 additions & 0 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<h2>Product</h2>

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

<% @products.each do |p| %>

<%= p.name %>
R$<%= p.price %>
<% end %>

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.

50 changes: 0 additions & 50 deletions app/views/products/index.html.erb

This file was deleted.

17 changes: 9 additions & 8 deletions app/views/products/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<h1>New product</h1>
<h1>Cadastro de Produto</h1>

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

<br>

<div>
<%= link_to "Back to products", products_path %>
</div>
<%= form_with(model: @product) do |f| %>
<%= f.label :name, 'Produto' %>
<%= f.text_field :name %>
<%= f.label :price, 'Preço' %>
<%= f.number_field :price %>
<%= f.label :product_category_id, 'Categoria' %>
<%= f.collection_select :product_category_id, @product_categories, :id, :name %>
<% 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.

8 changes: 2 additions & 6 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
Rails.application.routes.draw do
resources :products
resources :product_categories, only: [:create, :show] do
resources :products, only: [:create]
end
devise_for :users
root 'welcome#index'
root 'home#index'
resources :products, only: [:new, :create]
end
11 changes: 6 additions & 5 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
# movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }])
# Character.create(name: "Luke", movie: movies.first)

User.create(email: user@email.com, password: )
Company.create(name: , cnpj: )
Product.create(name: , price: , company: )
# User.create(email: user@email.com, password:)
# Company.create(name: , cnpj: )
# Product.create(name: , price: , company:)
#User.create(email: user@email.com, password: )


product_category = ProductCategory.create!(name: "Eletrônico")
product = Product.create!(name: "Celular", price: 2000, product_category: product_category)




User.create(email: user@email.com, password: )
Loading