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 @@ -
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| %> +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