Class: Bible270::ProfilesController
Overview
A reader editing their own name — the one thing about themselves they can
change. Everything else about a reader comes from how they signed in.
Constant Summary
ApplicationController::REMEMBER_COOKIE
Instance Method Summary
collapse
Instance Method Details
#edit ⇒ Object
9
10
11
|
# File 'app/controllers/bible270/profiles_controller.rb', line 9
def edit
@names = current_reader.suggested_names
end
|
#remove_avatar ⇒ Object
33
34
35
36
|
# File 'app/controllers/bible270/profiles_controller.rb', line 33
def remove_avatar
current_reader.remove_avatar!
redirect_to profile_path, notice: 'Your picture has been removed.'
end
|
#update ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'app/controllers/bible270/profiles_controller.rb', line 13
def update
problems = []
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
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
|