profile updater
This commit is contained in:
parent
94ae3c9687
commit
963517e4bb
@ -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
|
||||
|
@ -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
|
||||
|
@ -1,2 +1,28 @@
|
||||
<h1>Admin::Profile#edit</h1>
|
||||
<p>Find me in app/views/admin/profile/edit.html.erb</p>
|
||||
<%
|
||||
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| %>
|
||||
<div class="form-group">
|
||||
<%= form.label :name, "Full Name" %>
|
||||
<%= form.text_field :name %>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<%= form.label :email, "eMail" %>
|
||||
<%= form.email_field :email %>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<%= form.label :password, "New Password" %>
|
||||
<%= form.password_field :password %>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<%= form.label :password_confirmation, "New Password Confirmation" %>
|
||||
<%= form.password_field :password_confirmation %>
|
||||
</div>
|
||||
|
||||
<%= form.submit %>
|
||||
<% end %>
|
||||
|
@ -1,2 +1,8 @@
|
||||
<h1>Admin::Profile#view</h1>
|
||||
<p>Find me in app/views/admin/profile/view.html.erb</p>
|
||||
<%
|
||||
content_for :section_title, "Profile"
|
||||
%>
|
||||
|
||||
<p>Name: <%= current_admin.name %></p>
|
||||
<p>email: <%= current_admin.email %></p>
|
||||
<p>Role: <%= current_admin.role %></p>
|
||||
<%= link_to('Edit', admin_edit_profile_path, { class: 'btn' }) %>
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user