From 963517e4bb8ca0a5acbbee296536e5cdfd2ae627 Mon Sep 17 00:00:00 2001 From: Mark Moser Date: Wed, 24 Aug 2016 12:53:21 -0500 Subject: [PATCH] profile updater --- app/controllers/admin/profile_controller.rb | 15 ++++++++-- app/controllers/admin_controller.rb | 2 +- app/views/admin/profile/edit.html.erb | 30 +++++++++++++++++-- app/views/admin/profile/view.html.erb | 10 +++++-- .../admin/profile_controller_test.rb | 3 +- 5 files changed, 51 insertions(+), 9 deletions(-) diff --git a/app/controllers/admin/profile_controller.rb b/app/controllers/admin/profile_controller.rb index eb22f66..7fc32c9 100644 --- a/app/controllers/admin/profile_controller.rb +++ b/app/controllers/admin/profile_controller.rb @@ -1,16 +1,25 @@ module Admin - class ProfileController < ApplicationController + class ProfileController < AdminController def view end def edit + @user = current_admin end def update - redirect_to admin_profile_path + @user = current_admin + + if @user.update_attributes(user_params) + redirect_to admin_profile_path, + flash: { success: "Sucessfully updated profile" } + else + flash[:error] = "Failed to update profile." + render :edit + end end def lost_password - end + end end end diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 53313b0..37a79b4 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -1,6 +1,6 @@ class AdminController < ApplicationController layout 'admin' - before_action :authorize_admin, except: :styleguide + before_action :authorize_admin def dashboard @quizzes = Quiz.includes(:questions).all diff --git a/app/views/admin/profile/edit.html.erb b/app/views/admin/profile/edit.html.erb index cbb5227..d1014d2 100644 --- a/app/views/admin/profile/edit.html.erb +++ b/app/views/admin/profile/edit.html.erb @@ -1,2 +1,28 @@ -

Admin::Profile#edit

-

Find me in app/views/admin/profile/edit.html.erb

+<% + content_for :section_title, "Edit: #{@user.name}" +%> + +<%= render partial: 'shared/form_model_errors', locals: {obj: @user} %> +<%= form_for @user, url: admin_profile_url, method: :post do |form| %> +
+ <%= form.label :name, "Full Name" %> + <%= form.text_field :name %> +
+ +
+ <%= form.label :email, "eMail" %> + <%= form.email_field :email %> +
+ +
+ <%= form.label :password, "New Password" %> + <%= form.password_field :password %> +
+ +
+ <%= form.label :password_confirmation, "New Password Confirmation" %> + <%= form.password_field :password_confirmation %> +
+ + <%= form.submit %> +<% end %> diff --git a/app/views/admin/profile/view.html.erb b/app/views/admin/profile/view.html.erb index 492c480..92ff9b1 100644 --- a/app/views/admin/profile/view.html.erb +++ b/app/views/admin/profile/view.html.erb @@ -1,2 +1,8 @@ -

Admin::Profile#view

-

Find me in app/views/admin/profile/view.html.erb

+<% + content_for :section_title, "Profile" +%> + +

Name: <%= current_admin.name %>

+

email: <%= current_admin.email %>

+

Role: <%= current_admin.role %>

+<%= link_to('Edit', admin_edit_profile_path, { class: 'btn' }) %> diff --git a/test/controllers/admin/profile_controller_test.rb b/test/controllers/admin/profile_controller_test.rb index a60604e..f4f673f 100644 --- a/test/controllers/admin/profile_controller_test.rb +++ b/test/controllers/admin/profile_controller_test.rb @@ -18,8 +18,9 @@ module Admin end test "should post update" do - post admin_profile_url + post admin_profile_url, params: { user: { name: 'bobby tables' } } assert_redirected_to admin_profile_url + assert flash[:success] end test "should get lost_password" do