From d20dabf08e8b42c2920bc35052ae416a896d7f95 Mon Sep 17 00:00:00 2001 From: Dorothy Thurston Date: Thu, 24 Apr 2014 11:24:48 -0400 Subject: [PATCH 1/3] Make nav links user type dependent --- app/controllers/employers_controller.rb | 2 ++ app/controllers/homes_controller.rb | 4 ++++ app/controllers/types_controller.rb | 5 +++++ app/controllers/users_controller.rb | 8 +++++++- app/models/employer.rb | 2 +- app/models/user.rb | 12 ++++++++++++ app/views/employers/edit.html.erb | 0 app/views/employers/show.html.erb | 0 app/views/layouts/application.html.erb | 17 ++++++++++++----- app/views/minds/show.html.erb | 4 ++++ app/views/types/show.html.erb | 7 +++++++ app/views/users/edit.html.erb | 5 +---- config/routes.rb | 3 +++ 13 files changed, 58 insertions(+), 11 deletions(-) create mode 100644 app/controllers/employers_controller.rb create mode 100644 app/controllers/types_controller.rb create mode 100644 app/views/employers/edit.html.erb create mode 100644 app/views/employers/show.html.erb create mode 100644 app/views/types/show.html.erb diff --git a/app/controllers/employers_controller.rb b/app/controllers/employers_controller.rb new file mode 100644 index 0000000..2be3299 --- /dev/null +++ b/app/controllers/employers_controller.rb @@ -0,0 +1,2 @@ +class EmployersController < ApplicationController +end diff --git a/app/controllers/homes_controller.rb b/app/controllers/homes_controller.rb index b9dbcfe..ebf906e 100644 --- a/app/controllers/homes_controller.rb +++ b/app/controllers/homes_controller.rb @@ -11,4 +11,8 @@ def goto_dashboard redirect_to dashboard_path end + def choose_account_type + redirect_to type_path + end + end diff --git a/app/controllers/types_controller.rb b/app/controllers/types_controller.rb new file mode 100644 index 0000000..4888117 --- /dev/null +++ b/app/controllers/types_controller.rb @@ -0,0 +1,5 @@ +class TypesController < ApplicationController + def show + @user = current_user + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 146b9cc..dbfa382 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -11,7 +11,13 @@ def edit def update @user = current_user @user.update(user_params) - redirect_to mind_path(@user) + if current_user.employer? + redirect_to dashboard_path + elsif current_user.mind? + redirect_to mind_path(@user) + else + redirect_to type_path + end end private diff --git a/app/models/employer.rb b/app/models/employer.rb index d3b037a..edb7153 100644 --- a/app/models/employer.rb +++ b/app/models/employer.rb @@ -1,5 +1,5 @@ class Employer < User has_one :employer_profile accepts_nested_attributes_for :employer_profile - delegate :company_name, :company_url to:, :employer_profile + delegate :company_name, :company_url, to: :employer_profile end diff --git a/app/models/user.rb b/app/models/user.rb index 050ca6b..dd5c0b5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -17,4 +17,16 @@ def name email end end + + def no_type? + type.empty? + end + + def employer? + type == "Employer" + end + + def mind? + type == "Mind" + end end diff --git a/app/views/employers/edit.html.erb b/app/views/employers/edit.html.erb new file mode 100644 index 0000000..e69de29 diff --git a/app/views/employers/show.html.erb b/app/views/employers/show.html.erb new file mode 100644 index 0000000..e69de29 diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 9e11449..228b610 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -16,11 +16,18 @@ diff --git a/app/views/minds/show.html.erb b/app/views/minds/show.html.erb index f45dba7..25bb262 100644 --- a/app/views/minds/show.html.erb +++ b/app/views/minds/show.html.erb @@ -1,5 +1,9 @@

<%= @user.name %>

+
+ <%= @user.type %> +
+
Phone: <%= @user.telephone %>
diff --git a/app/views/types/show.html.erb b/app/views/types/show.html.erb new file mode 100644 index 0000000..154db55 --- /dev/null +++ b/app/views/types/show.html.erb @@ -0,0 +1,7 @@ +

Choose your account type

+<%= form_for @user.becomes(User), url: user_path(@user) do |form|%> +
+ <%= form.select :type, User::TYPES, include_blank: "User Type" %> +
+ <%= form.submit "Update Account type" %> +<% end %> diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index a4b3fd4..6d60991 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -1,6 +1,4 @@ -

Update profile

-

Update contact information:

- +

Update User Account information:

<%= form_for @user.becomes(User), url: user_path(@user) do |form|%>
<%= form.select :type, User::TYPES, include_blank: "User Type" %> @@ -20,7 +18,6 @@
<%= form.telephone_field :telephone, placeholder: "Phone Number" %>
-

Update links to your personal pages:

<%= hidden_field_tag(has_profile: :true) %> <%= form.submit "Update Personal Information" %>
diff --git a/config/routes.rb b/config/routes.rb index 23c4076..1484771 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,8 +2,11 @@ root 'homes#show' + resource :type, only: [:show] resources :users, only: [:new, :edit, :show, :update] + resources :employers, only: [:edit,:show] + resources :minds, only: [:show, :edit, :update] do resources :projects, only: [:new, :create, :show] resources :proficiencies From c95351239392ca9af7d66ffaaf087370a373c4dd Mon Sep 17 00:00:00 2001 From: Dorothy Thurston Date: Thu, 24 Apr 2014 11:50:45 -0400 Subject: [PATCH 2/3] Remove extra div --- app/controllers/homes_controller.rb | 5 ----- app/views/layouts/application.html.erb | 2 +- app/views/minds/show.html.erb | 1 - 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/app/controllers/homes_controller.rb b/app/controllers/homes_controller.rb index ebf906e..23d2e88 100644 --- a/app/controllers/homes_controller.rb +++ b/app/controllers/homes_controller.rb @@ -10,9 +10,4 @@ def show def goto_dashboard redirect_to dashboard_path end - - def choose_account_type - redirect_to type_path - end - end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 228b610..7e2d89c 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -26,8 +26,8 @@
  • <%= link_to "Profile", mind_path(current_user) %>
  • <%= link_to "Projects", projects_path %>
  • <%= link_to "Skills", mind_proficiencies_path(current_user) %>
  • -
  • <%= link_to 'Sign out', sign_out_path, method: :delete %>
  • <% end %> +
  • <%= link_to 'Sign out', sign_out_path, method: :delete %>
  • <% end %>
    diff --git a/app/views/minds/show.html.erb b/app/views/minds/show.html.erb index 25bb262..5dde05c 100644 --- a/app/views/minds/show.html.erb +++ b/app/views/minds/show.html.erb @@ -3,7 +3,6 @@
    <%= @user.type %>
    -
    Phone: <%= @user.telephone %>
    From 72d5113ae81777a7574d20530c600b44e36b3a67 Mon Sep 17 00:00:00 2001 From: Dorothy Thurston Date: Thu, 24 Apr 2014 13:48:24 -0400 Subject: [PATCH 3/3] Update no_type method and syntax errors --- app/controllers/employers_controller.rb | 5 +++++ app/models/user.rb | 6 +++--- app/views/types/show.html.erb | 2 +- config/routes.rb | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/controllers/employers_controller.rb b/app/controllers/employers_controller.rb index 2be3299..ffa1084 100644 --- a/app/controllers/employers_controller.rb +++ b/app/controllers/employers_controller.rb @@ -1,2 +1,7 @@ class EmployersController < ApplicationController + def show + end + + def edit + end end diff --git a/app/models/user.rb b/app/models/user.rb index dd5c0b5..5b278aa 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -19,14 +19,14 @@ def name end def no_type? - type.empty? + %w(Employer Mind).exclude?(type) end def employer? - type == "Employer" + type == 'Employer' end def mind? - type == "Mind" + type == 'Mind' end end diff --git a/app/views/types/show.html.erb b/app/views/types/show.html.erb index 154db55..5b40642 100644 --- a/app/views/types/show.html.erb +++ b/app/views/types/show.html.erb @@ -3,5 +3,5 @@
    <%= form.select :type, User::TYPES, include_blank: "User Type" %>
    - <%= form.submit "Update Account type" %> + <%= form.submit "Update User type" %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index 1484771..0f01c5f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,7 +5,7 @@ resource :type, only: [:show] resources :users, only: [:new, :edit, :show, :update] - resources :employers, only: [:edit,:show] + resources :employers, only: [:edit, :show] resources :minds, only: [:show, :edit, :update] do resources :projects, only: [:new, :create, :show]