13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'app/controllers/bible270/profiles_controller.rb', line 13
def update
problems = []
current_reader.update_column(:notify_on_mention, params[:notify_on_mention].present?)
problems << 'both a first and last name' unless current_reader.update_names(params[:first_name],
params[:last_name])
if params[:bible_version].present? && !current_reader.update_bible_version(params[:bible_version])
problems << 'a translation from the list'
end
source = params[:passage_source].presence || Reader::DEFAULT_PASSAGE_SOURCE
problems << 'a reading-link source from the list' unless current_reader.update_passage_source(source)
if params[:avatar].present? && !current_reader.attach_avatar(params[:avatar])
problems << (current_reader.errors[:avatar].first || 'a valid image')
end
if problems.empty?
redirect_to reader_path(current_reader), notice: 'Your profile has been updated.'
else
@names = { first_name: params[:first_name], last_name: params[:last_name] }
flash.now[:alert] = "Please give #{problems.to_sentence}."
render :edit, status: :unprocessable_entity
end
end
|