Simple user updating

This will probably not be done through management, but 1) there should
still be a way to update a user through the management interface, and 2)
it'll be easy to copy this code over to the public interface later.
This commit is contained in:
Andrew Radev 2015-05-24 12:28:05 +03:00
parent 2b64461ac9
commit cddab7a27e
5 changed files with 81 additions and 6 deletions

View File

@ -14,10 +14,42 @@ module Management
@profile = @user.speaker_profile @profile = @user.speaker_profile
end end
def edit
@user = find_user
@user.build_speaker_profile
end
def update
@user = find_user
if @user.update_attributes(user_params)
redirect_to [:management, @user]
else
render action: 'edit'
end
end
private private
def find_user def find_user
User.find(params[:id]) User.find(params[:id])
end end
def user_params
params.require(:user).permit(
:email,
speaker_profile_attributes: [
:picture,
:first_name,
:last_name,
:mobile_phone,
:biography,
:organisation,
:public_email,
:github,
:twitter,
]
)
end
end end
end end

View File

@ -0,0 +1,35 @@
- content_for :title
=> t 'actions.edit.title', model: User.model_name.human
= @user.name
.row
.col-lg-12
= simple_nested_form_for [:management, @user], wrapper: :horizontal_form, html: { class: 'form-horizontal' } do |f|
.panel.panel-primary
.panel-heading
h1.panel-title = t 'views.user.info'
.panel-body
.row
.col-lg-12
= f.input :email
hr
.row
.col-lg-12
= f.simple_fields_for :speaker_profile do |ff|
= ff.input :picture, wrapper: :horizontal_file_input
-# Required
= ff.input :first_name
= ff.input :last_name
= ff.input :mobile_phone
= ff.input :biography
-# Optional
= ff.input :organisation
= ff.input :public_email
= ff.input :github
= ff.input :twitter
.panel-footer.text-right
= f.submit class: 'btn btn-primary'

View File

@ -2,10 +2,14 @@
= @user.name = @user.name
.row .row
.col-lg-12 .col-lg-2
- if @profile.present? and @profile.picture.present?
= image_tag(@profile.picture.medium.url)
- else
-# TODO photo placeholder, default user image
.col-lg-10
h1.page-header h1.page-header
// - if @profile.present?
// = image_tag(@profile.picture.medium.url)
= @user.name = @user.name
- if @profile.present? - if @profile.present?

View File

@ -3,3 +3,5 @@ bg:
conference: conference:
info: Информация за конференция info: Информация за конференция
see_details: Повече информация see_details: Повече информация
user:
info: Информация за потребител

View File

@ -1,5 +1,7 @@
en: en:
views: views:
conference: conference:
info: Details about conference info: Conference details
see_details: See details see_details: See details
user:
info: User details