aboutsummaryrefslogtreecommitdiff
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/resources_controller.rb31
1 files changed, 14 insertions, 17 deletions
diff --git a/app/controllers/resources_controller.rb b/app/controllers/resources_controller.rb
index 2fa392f..4a99f2a 100644
--- a/app/controllers/resources_controller.rb
+++ b/app/controllers/resources_controller.rb
@@ -3,7 +3,8 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
class ResourcesController < ApplicationController
- before_action :set_resource, only: [:new, :show, :edit, :update, :delete, :destroy]
+ before_action :set_resource, only: [:show, :delete, :destroy]
+# before_action :set_resource_form, only: [:new, :create, :edit, :update]
# GET /resources
def index
@@ -12,6 +13,7 @@ class ResourcesController < ApplicationController
# GET /resources/new
def new
+ @resource = ResourceForm.new(current_agent)
end
# POST /resources
@@ -19,18 +21,12 @@ class ResourcesController < ApplicationController
# TODO Background job to list similar items
# TODO If there's a match, return to user with new record or list of mergeable ones
- classification = resource_params.delete(:classification) || { section_ids: [] }
-
- Rails.logger.info resource_params
-
- @resource = current_agent.resources.build(resource_params)
+ @resource = ResourceForm.new(current_agent, resource_form_params)
respond_to do |format|
- Rails.logger.info "format: #{format} - Res: #{@resource.inspect}"
if @resource.save
- classification[:section_ids].each { |id| @resource.classifications.find_or_create_by(section_id: id) }
- format.html { redirect_to @resource, notice: 'Merci de votre contribution !' }
- format.json { render :show, status: :created, location: @resource }
+ format.html { redirect_to @resource.resource, notice: 'Merci de votre contribution !' }
+ format.json { render :show, status: :created, location: @resource.resource }
else
format.html { render :new }
format.json { render json: @resource.errors, status: :unprocessable_entity }
@@ -62,8 +58,8 @@ class ResourcesController < ApplicationController
respond_to do |format|
if @resource.update(resource_params)
- format.html { redirect_to @resource, notice: 'Merci de votre contribution !' }
- format.json { render :show, status: :ok, location: @resource }
+ format.html { redirect_to @resource.resource, notice: 'Merci de votre contribution !' }
+ format.json { render :show, status: :ok, location: @resource.resource }
else
format.html { render :edit }
format.json { render json: @resource.errors, status: :unprocessable_entity }
@@ -97,9 +93,9 @@ class ResourcesController < ApplicationController
private
- def resource_params
+ def resource_form_params
params
- .require(:resource)
+ .require(:resource_form)
.permit(:agent_id,
:uuid,
:name,
@@ -111,11 +107,12 @@ class ResourcesController < ApplicationController
:address,
:postal_code,
:city,
- :entry_number,
- :categories,
+ :entry_number, # Unused on new resources
+ :categories, #
:latitude,
:longitude,
- classification: [ :section_ids ])
+ :source,
+ section_ids: [])
end
def set_resource