From 78a69a77fb27f871b4bc28d52701495f158e576b Mon Sep 17 00:00:00 2001 From: Chris Talib Date: Fri, 15 Dec 2017 07:18:11 +0100 Subject: [PATCH 1/7] adding a user controller, route and view page, basic config not working yet' ' --- app/controllers/points_controller.rb | 1 - app/controllers/users_controller.rb | 5 +++++ app/views/users/show.html.erb | 3 +++ config/routes.rb | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 app/controllers/users_controller.rb create mode 100644 app/views/users/show.html.erb diff --git a/app/controllers/points_controller.rb b/app/controllers/points_controller.rb index b6e2031b..c522c168 100644 --- a/app/controllers/points_controller.rb +++ b/app/controllers/points_controller.rb @@ -1,4 +1,3 @@ - class PointsController < ApplicationController before_action :set_point, only: [:show, :edit,:featured, :update, :destroy] diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 00000000..b7fac167 --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,5 @@ +class UsersController < ApplicationController + def show + @user = User.find(params[:id]) + end +end diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb new file mode 100644 index 00000000..6cb00b9a --- /dev/null +++ b/app/views/users/show.html.erb @@ -0,0 +1,3 @@ +

Hello <%= User.name %>!

+ + diff --git a/config/routes.rb b/config/routes.rb index 2b2747f9..77064fcc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -19,6 +19,7 @@ end resources :services resources :topics + resources :users namespace :api, defaults: { format: :json } do namespace :v1 do From 756b3c15c7525763200e8d575a36d15fb43aa933 Mon Sep 17 00:00:00 2001 From: Chris Talib Date: Fri, 15 Dec 2017 07:27:53 +0100 Subject: [PATCH 2/7] starting to configure the view --- app/controllers/users_controller.rb | 16 ++++++++++++++++ app/views/users/show.html.erb | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index b7fac167..bf6cc860 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,5 +1,21 @@ class UsersController < ApplicationController + before_action :set_user + + def show + end + + def edit + end + + def destroy + @user.destroy + flash[:notice] = "Your account has been deleted! Goodbye!" + redirect_to root_path + end + + private + def set_user @user = User.find(params[:id]) end end diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 6cb00b9a..78aad622 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,3 +1,18 @@ -

Hello <%= User.name %>!

+

Hello <%= current_user.username.nil? ? "you" : current_user.username %>!

+ +

Here is your dashboard:

+ + + + From 4b03954c310a7c323998af1a2e2188927fe8f4b3 Mon Sep 17 00:00:00 2001 From: Chris Talib Date: Fri, 15 Dec 2017 07:33:48 +0100 Subject: [PATCH 3/7] adding change details path --- app/controllers/users_controller.rb | 1 + app/views/users/show.html.erb | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index bf6cc860..a860871f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -10,6 +10,7 @@ def edit def destroy @user.destroy + flash[:confirmation] = "Are your sure you want to delete your account?" flash[:notice] = "Your account has been deleted! Goodbye!" redirect_to root_path end diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 78aad622..3ffb551f 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -3,10 +3,8 @@

Here is your dashboard:

    -
  • Edit your username
  • -
  • Edit your email
  • -
  • Reset your password
  • -
  • Delete your account
  • +
  • <%= link_to 'Edit your details', edit_user_registration_path %>
  • +
  • <%= link_to 'Delete your account', destroy_user_path %>
- - diff --git a/config/routes.rb b/config/routes.rb index 77064fcc..2b2747f9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -19,7 +19,6 @@ end resources :services resources :topics - resources :users namespace :api, defaults: { format: :json } do namespace :v1 do From 81bf8caff72cb470ae5e8e367f5fa7bd64025452 Mon Sep 17 00:00:00 2001 From: Chris Talib Date: Fri, 15 Dec 2017 07:56:43 +0100 Subject: [PATCH 6/7] did some minor styling --- app/views/devise/registrations/edit.html.erb | 44 +++++++++++--------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index e082f761..3f2e78a4 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -1,28 +1,34 @@ -

Edit <%= resource_name.to_s.humanize %>

+
+
-<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> - <%= f.error_notification %> -
- <%= f.input :username, required: true, autofocus: true %> - <%= f.input :email, required: true, autofocus: true %> +

Edit <%= resource_name.to_s.humanize %>

- <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> + <%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> + <%= f.error_notification %> + +
+ <%= f.input :username, required: true, autofocus: true %> + <%= f.input :email, required: true, autofocus: true %> + + <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>

Currently waiting confirmation for: <%= resource.unconfirmed_email %>

- <% end %> + <% end %> - <%= f.input :password, autocomplete: "off", hint: "leave it blank if you don't want to change it", required: false %> - <%= f.input :password_confirmation, required: false %> - <%= f.input :current_password, hint: "we need your current password to confirm your changes", required: true %> -
+ <%= f.input :password, autocomplete: "off", hint: "leave it blank if you don't want to change it", required: false %> + <%= f.input :password_confirmation, required: false %> + <%= f.input :current_password, hint: "we need your current password to confirm your changes", required: true %> +
-
- <%= f.button :submit, "Update" %> -
-<% end %> +
+ <%= f.button :submit, "Update" %> +
+ <% end %> -

Cancel my account

+

Cancel my account

-

Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %>

+

Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %>

-<%= link_to "Back", :back %> + <%= link_to "Back", :back %> +
+
From 9a9ff5b74ef8b36c657b318499e8bed265c38882 Mon Sep 17 00:00:00 2001 From: Chris Talib Date: Fri, 15 Dec 2017 15:22:04 +0100 Subject: [PATCH 7/7] adding font awesome icon --- app/views/shared/_navbar.html.erb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/shared/_navbar.html.erb b/app/views/shared/_navbar.html.erb index 49d144cf..2107a2e0 100644 --- a/app/views/shared/_navbar.html.erb +++ b/app/views/shared/_navbar.html.erb @@ -44,7 +44,9 @@ <% end %>
  • - <%= link_to "Setting", edit_user_registration_path %> + <%= link_to edit_user_registration_path do %> + <%= t(".profile", default: "Settings") %> + <% end %>
  • <%= link_to destroy_user_session_path, method: :delete do %>