From cddab7a27ef15933589b383741391e7e699fe908 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sun, 24 May 2015 12:28:05 +0300 Subject: [PATCH] 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. --- .../management/users_controller.rb | 32 +++++++++++++++++ app/views/management/users/edit.html.slim | 35 +++++++++++++++++++ app/views/management/users/show.html.slim | 10 ++++-- config/locales/views.bg.yml | 4 ++- config/locales/views.en.yml | 6 ++-- 5 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 app/views/management/users/edit.html.slim diff --git a/app/controllers/management/users_controller.rb b/app/controllers/management/users_controller.rb index bb5107b..c1d75f4 100644 --- a/app/controllers/management/users_controller.rb +++ b/app/controllers/management/users_controller.rb @@ -14,10 +14,42 @@ module Management @profile = @user.speaker_profile 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 def find_user User.find(params[:id]) 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 diff --git a/app/views/management/users/edit.html.slim b/app/views/management/users/edit.html.slim new file mode 100644 index 0000000..c0316b9 --- /dev/null +++ b/app/views/management/users/edit.html.slim @@ -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' diff --git a/app/views/management/users/show.html.slim b/app/views/management/users/show.html.slim index 22b9aa2..d68b2dd 100644 --- a/app/views/management/users/show.html.slim +++ b/app/views/management/users/show.html.slim @@ -2,10 +2,14 @@ = @user.name .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 - // - if @profile.present? - // = image_tag(@profile.picture.medium.url) = @user.name - if @profile.present? diff --git a/config/locales/views.bg.yml b/config/locales/views.bg.yml index aefd993..bcb1c79 100644 --- a/config/locales/views.bg.yml +++ b/config/locales/views.bg.yml @@ -2,4 +2,6 @@ bg: views: conference: info: Информация за конференция - see_details: Повече информация \ No newline at end of file + see_details: Повече информация + user: + info: Информация за потребител diff --git a/config/locales/views.en.yml b/config/locales/views.en.yml index fbd6e96..60bbcc5 100644 --- a/config/locales/views.en.yml +++ b/config/locales/views.en.yml @@ -1,5 +1,7 @@ en: views: conference: - info: Details about conference - see_details: See details \ No newline at end of file + info: Conference details + see_details: See details + user: + info: User details