Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
open-source
aoz-003
Commits
e2b34e3c
Commit
e2b34e3c
authored
Jun 29, 2017
by
Kaspar Vollenweider
👻
Committed by
Kaspar
Jun 30, 2017
Browse files
validate presence of first and lastname
parent
2bcbb80f
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/controllers/volunteers_controller.rb
View file @
e2b34e3c
...
...
@@ -21,8 +21,6 @@ class VolunteersController < ApplicationController
def
create
@volunteer
=
Volunteer
.
new
(
volunteer_params
)
@volunteer
.
schedules
<<
Schedule
.
build
@volunteer
.
build_contact
@volunteer
.
registrar
=
current_user
authorize
@volunteer
if
@volunteer
.
save
...
...
@@ -36,7 +34,8 @@ class VolunteersController < ApplicationController
state_was_registered
=
@volunteer
.
registered?
return
render
:edit
unless
@volunteer
.
update
(
volunteer_params
)
if
state_was_registered
&&
@volunteer
.
accepted?
&&
invite_volunteer_user
redirect_to
volunteers_path
,
notice:
t
(
'invite_sent'
,
email:
@volunteer
.
contact
.
contact_emails
.
first
.
body
)
redirect_to
volunteers_path
,
notice:
t
(
'invite_sent'
,
email:
@volunteer
.
contact
.
contact_emails
.
first
.
body
)
else
redirect_to
@volunteer
,
notice:
t
(
'volunteer_updated'
)
end
...
...
app/models/contact.rb
View file @
e2b34e3c
class
Contact
<
ApplicationRecord
belongs_to
:contactable
,
polymorphic:
true
,
optional:
true
validates
:last_name
,
presence:
true
,
if: :department?
has_many
:contact_emails
accepts_nested_attributes_for
:contact_emails
,
allow_destroy:
true
has_many
:contact_phones
accepts_nested_attributes_for
:contact_phones
,
allow_destroy:
true
validates
:last_name
,
presence:
true
validates
:first_name
,
presence:
true
,
unless: :department?
def
to_s
last_name
end
def
full_name
"
#{
try
(
:first_name
)
}
#{
last_name
}
"
"
#{
try
(
:first_name
)
}
#{
try
(
:
last_name
)
}
"
end
def
department?
contactable_type
==
'Department'
end
def
volunteer?
contactable_type
==
'Volunteer'
end
end
app/models/volunteer.rb
View file @
e2b34e3c
...
...
@@ -2,14 +2,20 @@ class Volunteer < ApplicationRecord
include
AssociatableFields
include
GenderCollection
include
FullName
acts_as_paranoid
before_save
:default_state
has_one
:contact
,
as: :contactable
accepts_nested_attributes_for
:contact
has_one
:first_language
acts_as_paranoid
belongs_to
:user
,
optional:
true
before_save
:default_state
belongs_to
:registrar
,
optional:
true
,
class_name:
'User'
,
foreign_key:
'registrar_id'
has_attached_file
:avatar
,
styles:
{
thumb:
'100x100#'
}
REGISTERED
=
'registered'
.
freeze
ACCEPTED
=
'accepted'
.
freeze
...
...
@@ -19,12 +25,7 @@ class Volunteer < ApplicationRecord
STATES_FOR_REVIEWED
=
[
ACCEPTED
,
REJECTED
,
INACTIVE
,
RESIGNED
].
freeze
STATES
=
[
REGISTERED
]
+
STATES_FOR_REVIEWED
belongs_to
:user
,
optional:
true
belongs_to
:registrar
,
optional:
true
,
class_name:
'User'
,
foreign_key:
'registrar_id'
has_attached_file
:avatar
,
styles:
{
thumb:
'100x100#'
}
validates
:contact
,
presence:
true
validates
:state
,
inclusion:
{
in:
STATES
}
validates_attachment
:avatar
,
content_type:
{
content_type:
/\Aimage\/.*\z/
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment