From 6bcecbd219f1b4482a8544306f7e2011eb75ccfa Mon Sep 17 00:00:00 2001 From: Stella Rouzi Date: Sun, 1 May 2016 18:50:07 +0300 Subject: [PATCH 1/2] fix admin/registrations#update --- app/controllers/admin/registrations_controller.rb | 3 +++ app/views/admin/registrations/edit.html.haml | 4 +++- app/views/admin/registrations/index.html.haml | 9 +++++---- app/views/admin/users/index.html.haml | 8 ++++---- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/controllers/admin/registrations_controller.rb b/app/controllers/admin/registrations_controller.rb index 38b54ac1..7f80297c 100644 --- a/app/controllers/admin/registrations_controller.rb +++ b/app/controllers/admin/registrations_controller.rb @@ -14,6 +14,9 @@ module Admin def edit; end def update + @user.update_attributes(registration_params[:user_attributes]) + params[:registration].delete :user_attributes + @registration.update_attributes(registration_params) if @registration.save redirect_to admin_conference_registrations_path(@conference.short_title), diff --git a/app/views/admin/registrations/edit.html.haml b/app/views/admin/registrations/edit.html.haml index 0cd19eea..88450883 100644 --- a/app/views/admin/registrations/edit.html.haml +++ b/app/views/admin/registrations/edit.html.haml @@ -2,7 +2,9 @@ .col-md-12 .page-header %h1 - Registration for #{@user.username} + Registration for #{@user.username} (#{@user.email}) + + = link_to 'Edit User', edit_admin_user_path(@user), class: 'btn btn-primary pull-right' if can? :edit, @user .row .col-md-6 = semantic_form_for(@registration, url: admin_conference_registration_path(@conference.short_title, @registration)) do |f| diff --git a/app/views/admin/registrations/index.html.haml b/app/views/admin/registrations/index.html.haml index d3ac590b..11ab9144 100644 --- a/app/views/admin/registrations/index.html.haml +++ b/app/views/admin/registrations/index.html.haml @@ -27,10 +27,11 @@ %td = registration.id %td - = registration.name - - registration.user.roles.each do |role| - - if role.resource == @conference - %span.label.label-info= role.name.titleize + = registration.name.present? ? registration.name : registration.username + %br + - registration.user.roles.where(resource: @conference).each do |role| + %span.label.label-info + = role.name.titleize %td = registration.email %td diff --git a/app/views/admin/users/index.html.haml b/app/views/admin/users/index.html.haml index 7752a41e..c3d7b672 100644 --- a/app/views/admin/users/index.html.haml +++ b/app/views/admin/users/index.html.haml @@ -40,9 +40,9 @@ = '...' - else None - - if can? :show, user - %td + %td + - if can? :show, user = link_to 'View', admin_user_path(user), class: 'btn btn-success' - - if can? :update, user - %td + %td + - if can? :update, user = link_to 'Edit', edit_admin_user_path(user), class: 'btn btn-primary' From 9fe7d0ca7c014ff5a4ad9ded28236a4bdefee161 Mon Sep 17 00:00:00 2001 From: Stella Rouzi Date: Mon, 2 May 2016 18:02:57 +0300 Subject: [PATCH 2/2] Use strong parameters for user in admin/registrations#update --- app/controllers/admin/registrations_controller.rb | 10 ++++++---- app/views/admin/registrations/edit.html.haml | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/controllers/admin/registrations_controller.rb b/app/controllers/admin/registrations_controller.rb index 7f80297c..9c60ca14 100644 --- a/app/controllers/admin/registrations_controller.rb +++ b/app/controllers/admin/registrations_controller.rb @@ -14,8 +14,7 @@ module Admin def edit; end def update - @user.update_attributes(registration_params[:user_attributes]) - params[:registration].delete :user_attributes + @user.update_attributes(user_params) @registration.update_attributes(registration_params) if @registration.save @@ -54,11 +53,14 @@ module Admin @user = User.find_by(id: @registration.user_id) end + def user_params + params.require(:user).permit(:name, :nickname, :affiliation) + end + def registration_params params.require(:registration).permit(:user_id, :conference_id, :arrival, :departure, :attended, :volunteer, :other_special_needs, - vchoice_ids: [], qanswer_ids: [], qanswers_attributes: [], event_ids: [], - user_attributes: [:nickname, :name, :affiliation, :tshirt, :mobile, :volunteer_experience, :languages]) + vchoice_ids: [], qanswer_ids: [], qanswers_attributes: [], event_ids: []) end end end diff --git a/app/views/admin/registrations/edit.html.haml b/app/views/admin/registrations/edit.html.haml index 88450883..b9b99769 100644 --- a/app/views/admin/registrations/edit.html.haml +++ b/app/views/admin/registrations/edit.html.haml @@ -9,7 +9,7 @@ .col-md-6 = semantic_form_for(@registration, url: admin_conference_registration_path(@conference.short_title, @registration)) do |f| = f.inputs 'Personal Information' do - = f.fields_for :user do |u| + = semantic_fields_for :user do |u| = u.input :name, as: :string = u.input :nickname, as: :string = u.input :affiliation, placeholder: 'Company/User Group/nothing', as: :string