generated from FGA0138-MDS-Ajax/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configuração das tabelas Users e Cargos
- Loading branch information
Showing
26 changed files
with
245 additions
and
109 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
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,70 @@ | ||
class CargosController < ApplicationController | ||
before_action :set_cargo, only: %i[ show edit update destroy ] | ||
|
||
# GET /cargos or /cargos.json | ||
def index | ||
@cargos = Cargo.all | ||
end | ||
|
||
# GET /cargos/1 or /cargos/1.json | ||
def show | ||
end | ||
|
||
# GET /cargos/new | ||
def new | ||
@cargo = Cargo.new | ||
end | ||
|
||
# GET /cargos/1/edit | ||
def edit | ||
end | ||
|
||
# POST /cargos or /cargos.json | ||
def create | ||
@cargo = Cargo.new(cargo_params) | ||
|
||
respond_to do |format| | ||
if @cargo.save | ||
format.html { redirect_to cargo_url(@cargo), notice: "Cargo was successfully created." } | ||
format.json { render :show, status: :created, location: @cargo } | ||
else | ||
format.html { render :new, status: :unprocessable_entity } | ||
format.json { render json: @cargo.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PATCH/PUT /cargos/1 or /cargos/1.json | ||
def update | ||
respond_to do |format| | ||
if @cargo.update(cargo_params) | ||
format.html { redirect_to cargo_url(@cargo), notice: "Cargo was successfully updated." } | ||
format.json { render :show, status: :ok, location: @cargo } | ||
else | ||
format.html { render :edit, status: :unprocessable_entity } | ||
format.json { render json: @cargo.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /cargos/1 or /cargos/1.json | ||
def destroy | ||
@cargo.destroy! | ||
|
||
respond_to do |format| | ||
format.html { redirect_to cargos_url, notice: "Cargo was successfully destroyed." } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_cargo | ||
@cargo = Cargo.find(params[:id]) | ||
end | ||
|
||
# Only allow a list of trusted parameters through. | ||
def cargo_params | ||
params.require(:cargo).permit(:cargos) | ||
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,2 @@ | ||
module CargosHelper | ||
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,2 @@ | ||
class Cargo < ApplicationRecord | ||
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
class User < ApplicationRecord | ||
belongs_to :cargo | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
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,9 @@ | ||
class CreateCargos < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :cargos do |t| | ||
t.string :type | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
backend/db/migrate/20240518234753_create_user_join_table_cargos.rb
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 CreateUserJoinTableCargos < ActiveRecord::Migration[7.1] | ||
def change | ||
add_reference :users, :cargos, foreign_key: true | ||
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,48 @@ | ||
require "test_helper" | ||
|
||
class CargosControllerTest < ActionDispatch::IntegrationTest | ||
setup do | ||
@cargo = cargos(:one) | ||
end | ||
|
||
test "should get index" do | ||
get cargos_url | ||
assert_response :success | ||
end | ||
|
||
test "should get new" do | ||
get new_cargo_url | ||
assert_response :success | ||
end | ||
|
||
test "should create cargo" do | ||
assert_difference("Cargo.count") do | ||
post cargos_url, params: { cargo: { cargos: @cargo.cargos } } | ||
end | ||
|
||
assert_redirected_to cargo_url(Cargo.last) | ||
end | ||
|
||
test "should show cargo" do | ||
get cargo_url(@cargo) | ||
assert_response :success | ||
end | ||
|
||
test "should get edit" do | ||
get edit_cargo_url(@cargo) | ||
assert_response :success | ||
end | ||
|
||
test "should update cargo" do | ||
patch cargo_url(@cargo), params: { cargo: { cargos: @cargo.cargos } } | ||
assert_redirected_to cargo_url(@cargo) | ||
end | ||
|
||
test "should destroy cargo" do | ||
assert_difference("Cargo.count", -1) do | ||
delete cargo_url(@cargo) | ||
end | ||
|
||
assert_redirected_to cargos_url | ||
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,7 @@ | ||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
|
||
one: | ||
cargos: MyString | ||
|
||
two: | ||
cargos: MyString |
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 CargoTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |
Oops, something went wrong.