Commit aea92940 authored by Chrysanthi Lagodimou's avatar Chrysanthi Lagodimou
Browse files

nested attributes in controllers concern

parent 76565cdc
class ClientsController < ApplicationController
include NestedAttributes
before_action :set_client, only: [:show, :edit, :update, :destroy]
def index
......@@ -59,19 +61,11 @@ class ClientsController < ApplicationController
end
def client_params
params.require(:client).permit(
:id, :first_name, :last_name, :date_of_birth, :nationality, :permit, :gender,
:street, :zip, :city, :phone, :email, :goals, :education, :hobbies,
params.require(:client).permit(:id, :first_name, :last_name, :date_of_birth, :nationality,
:permit, :gender, :street, :zip, :city, :phone, :email, :goals, :education, :hobbies,
:interests, :state, :comments, :competent_authority, :involved_authority, :user_id,
language_skills_attributes: [
:id, :language, :level, :_destroy
],
relatives_attributes: [
:id, :first_name, :last_name, :date_of_birth, :relation, :_destroy
],
schedules_attributes: [
:id, :day, :time, :available
]
)
language_skills_attributes: language_skills_attributes,
relatives_attributes: relatives_attributes,
schedules_attributes: schedules_attributes)
end
end
module NestedAttributes
extend ActiveSupport::Concern
included do
def language_skills_attributes
[:id, :language, :level, :_destroy]
end
def relatives_attributes
[:id, :first_name, :last_name, :date_of_birth, :relation, :_destroy]
end
def schedules_attributes
[:id, :day, :time, :available]
end
end
end
class VolunteersController < ApplicationController
include NestedAttributes
before_action :set_volunteer, only: [:show, :edit, :update, :destroy]
def index
......@@ -48,14 +49,8 @@ class VolunteersController < ApplicationController
:education, :motivation, :experience, :expectations, :strengths, :skills, :interests, :state,
:duration, :man, :woman, :family, :kid, :sport, :creative, :music, :culture, :training,
:german_course, :adults, :teenagers, :children, :region,
language_skills_attributes: [
:id, :language, :level, :_destroy
],
relatives_attributes: [
:id, :first_name, :last_name, :date_of_birth, :relation, :_destroy
],
schedules_attributes: [
:id, :day, :time, :available
])
language_skills_attributes: language_skills_attributes,
relatives_attributes: relatives_attributes,
schedules_attributes: schedules_attributes)
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment