diff --git a/app/controllers/subproject_addresses_controller.rb b/app/controllers/subproject_addresses_controller.rb new file mode 100644 index 0000000..5fa93a0 --- /dev/null +++ b/app/controllers/subproject_addresses_controller.rb @@ -0,0 +1,49 @@ +class SubprojectAddressesController < ApplicationController + before_action :set_subproject_address, only: %i[show edit update destroy] + + def index + @subproject_addresses = SubprojectAddress.all + end + + def show + end + + def new + @subproject_address = SubprojectAddress.new + end + + def edit + end + + def create + @subproject_address = SubprojectAddress.new(subproject_address_params) + if @subproject_address.save + redirect_to @subproject_address, notice: "Adresse was successfully created." + else + render :new, status: :unprocessable_entity + end + end + + def update + if @subproject_address.update(subproject_address_params) + redirect_to @subproject_address, notice: "Adresse was successfully updated." + else + render :edit, status: :unprocessable_entity + end + end + + def destroy + @subproject_address.destroy + redirect_to subproject_addresses_url, notice: "Adresse was successfully destroyed." + end + + private + + def set_subproject_address + @subproject_address = SubprojectAddress.find(params[:id]) + end + + def subproject_address_params + params.require(:subproject_address).permit(:subproject_id, :streetname, :zipcode, :city, :country) + end +end \ No newline at end of file diff --git a/app/models/subproject_address.rb b/app/models/subproject_address.rb new file mode 100644 index 0000000..d96b910 --- /dev/null +++ b/app/models/subproject_address.rb @@ -0,0 +1,5 @@ +class SubprojectAddress < ApplicationRecord + belongs_to :subproject + + validates :streetname, :zipcode, :city, :country, presence: true +end \ No newline at end of file diff --git a/app/views/subproject_addresses/_form.html.erb b/app/views/subproject_addresses/_form.html.erb new file mode 100644 index 0000000..3e86f33 --- /dev/null +++ b/app/views/subproject_addresses/_form.html.erb @@ -0,0 +1,24 @@ +<%= form_with(model: subproject_address) do |form| %> + <% if subproject_address.errors.any? %> +
+

<%= pluralize(subproject_address.errors.count, "error") %> prohibited this client from being saved:

+ + +
+ <% end %> + + <% [:streetname, :zipcode, :city, :country].each do |attrib| %> +
+ <%= form.label attrib, style: "display: block" %> + <%= form.text_field attrib %> +
+ <% end %> + +
+ <%= form.submit %> +
+<% end %> diff --git a/app/views/subproject_addresses/_subproject_address.erb b/app/views/subproject_addresses/_subproject_address.erb new file mode 100644 index 0000000..48074fc --- /dev/null +++ b/app/views/subproject_addresses/_subproject_address.erb @@ -0,0 +1,22 @@ +
+

+ Streetname: + <%= subproject_address.streetname %> +

+ +

+ Zipcode: + <%= subproject_address.zipcode %> +

+ +

+ City: + <%= subproject_address.city %> +

+ +

+ Country: + <%= subproject_address.country %> +

+ +
diff --git a/app/views/subproject_addresses/edit.html.erb b/app/views/subproject_addresses/edit.html.erb new file mode 100644 index 0000000..c65a869 --- /dev/null +++ b/app/views/subproject_addresses/edit.html.erb @@ -0,0 +1,12 @@ +<% content_for :title, "Editing subproject address" %> + +

Editing subproject address

+ +<%= render "form", subproject_address: @subproject_address %> + +
+ +
+ <%= link_to "Show this subproject address", @subproject_address %> | + <%= link_to "Back to subproject addresses", subproject_addresses_path %> +
\ No newline at end of file diff --git a/app/views/subproject_addresses/index.html.erb b/app/views/subproject_addresses/index.html.erb new file mode 100644 index 0000000..b094e3c --- /dev/null +++ b/app/views/subproject_addresses/index.html.erb @@ -0,0 +1,18 @@ +

<%= notice %>

+ +<% content_for :title, "Subproject addresses" %> + +

Subproject addresses

+ +
+ <% @subproject_addresses.each do |subproject_address| %> + <%= render subproject_address %> +

+ <%= link_to "Show this subproject address", subproject_address %> +

+ <% end %> +
+ +<%= link_to "New subproject address", new_subproject_address_path %> + +<%= link_to "Back to main", "/" %> \ No newline at end of file diff --git a/app/views/subproject_addresses/new.html.erb b/app/views/subproject_addresses/new.html.erb new file mode 100644 index 0000000..9ee3a44 --- /dev/null +++ b/app/views/subproject_addresses/new.html.erb @@ -0,0 +1,11 @@ +<% content_for :title, "New subproject address" %> + +

New subproject address

+ +<%= render "form", subproject_address: @subproject_address %> + +
+ +
+ <%= link_to "Back to subproject addresses", subproject_addresses_path %> +
diff --git a/app/views/subproject_addresses/show.html.erb b/app/views/subproject_addresses/show.html.erb new file mode 100644 index 0000000..90871bf --- /dev/null +++ b/app/views/subproject_addresses/show.html.erb @@ -0,0 +1,10 @@ +

<%= notice %>

+ +<%= render @subproject_address %> + +
+ <%= link_to "Edit this subproject address", edit_subproject_address_path(@subproject_address) %> | + <%= link_to "Back to subproject addresses", subproject_addresses_path %> + + <%= button_to "Destroy this subproject address", @subproject_address, method: :delete %> +
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 5db00c0..115640c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,7 @@ Rails.application.routes.draw do resources :clients resources :subprojects + resources :subproject_addresses resources :projects # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html diff --git a/db/migrate/20250722152542_create_subproject_addresses.rb b/db/migrate/20250722152542_create_subproject_addresses.rb new file mode 100644 index 0000000..40ed309 --- /dev/null +++ b/db/migrate/20250722152542_create_subproject_addresses.rb @@ -0,0 +1,13 @@ +class CreateSubprojectAddresses < ActiveRecord::Migration[8.0] + def change + create_table :subproject_addresses do |t| + t.string :streetname + t.string :zipcode + t.string :city + t.string :country + t.text :notes + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 479cb6d..b6dae50 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2025_07_21_145904) do +ActiveRecord::Schema[8.0].define(version: 2025_07_22_152542) do create_table "clients", force: :cascade do |t| t.string "company_name" t.string "firstname" @@ -36,6 +36,16 @@ ActiveRecord::Schema[8.0].define(version: 2025_07_21_145904) do t.datetime "order_date" end + create_table "subproject_addresses", force: :cascade do |t| + t.string "streetname" + t.string "zipcode" + t.string "city" + t.string "country" + t.text "notes" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "subprojects", force: :cascade do |t| t.string "subproject_name" t.integer "project_id", null: false