From e548a9b17feae3635a9cefe5056ac13ae5b0a1e6 Mon Sep 17 00:00:00 2001 From: magicjascha Date: Mon, 15 Apr 2019 20:40:06 +0200 Subject: [PATCH] #110: edit as profile, use find_coach for admin accessibility of coach profile --- app/controllers/coaches_controller.rb | 40 ++++++++++++++++++--------- app/views/coaches/edit.html.erb | 8 ++++++ app/views/coaches/show.html.erb | 19 ++++++++++--- app/views/layouts/coach.html.erb | 10 ++++--- 4 files changed, 56 insertions(+), 21 deletions(-) create mode 100644 app/views/coaches/edit.html.erb diff --git a/app/controllers/coaches_controller.rb b/app/controllers/coaches_controller.rb index 1c1344d5..6c6eb326 100644 --- a/app/controllers/coaches_controller.rb +++ b/app/controllers/coaches_controller.rb @@ -10,25 +10,39 @@ def new def create @coach = Coach.new(coach_params) if @coach.save - redirect_to coach_url(@coach) + redirect_to edit_coach_path(@coach) else render :new end end + def edit + @coach = find_coach + end + + def update + @coach = Coach.find(params[:id]) + if !@coach.update(coach_params) + render :edit + end + end + def show - @user = current_user - @coach = @user.coach + @coach = Coach.find(params[:id]) end - + private - def coach_params - params.require(:coach).permit(:name, - :female, - :language_en, - :language_de, - :notifications, - user_attributes: [:email,:password]) - end - + def coach_params + params.require(:coach).permit(:name, + :female, + :language_en, + :language_de, + :notifications, + user_attributes: [:email,:password]) + end + + def find_coach + Coach.find(params[:id]) + end + end \ No newline at end of file diff --git a/app/views/coaches/edit.html.erb b/app/views/coaches/edit.html.erb new file mode 100644 index 00000000..21ef622e --- /dev/null +++ b/app/views/coaches/edit.html.erb @@ -0,0 +1,8 @@ +

Your coach account

+<%= link_to("View Public Profile", coach_path(@coach)) %> +<%= form_for(@coach, html: {class: "grey"}, method: :put) do |f| %> + <%= render 'shared/coachform', :f => f %> +
+ <%= f.submit "Submit", class: 'commit', type: 'submit' %> +
+<% end %> diff --git a/app/views/coaches/show.html.erb b/app/views/coaches/show.html.erb index d4e6ef2e..31b2ee1e 100644 --- a/app/views/coaches/show.html.erb +++ b/app/views/coaches/show.html.erb @@ -1,4 +1,15 @@ -

Your coach account

-<%= form_for @coach, html: {class: "grey"} do |f| %> - <%= render 'shared/coachform', :f => f %> -<% end %> \ No newline at end of file +

Coach <%= @coach.name %>

+ + + + + + + + + + + + + +
Female<%= @coach.female %>
gives talks in German<%= @coach.language_de %>
gives talks in English<%= @coach.language_en %>
\ No newline at end of file diff --git a/app/views/layouts/coach.html.erb b/app/views/layouts/coach.html.erb index 6040ecb4..0c7d8208 100644 --- a/app/views/layouts/coach.html.erb +++ b/app/views/layouts/coach.html.erb @@ -2,16 +2,18 @@ <%= yield %> <% end %> \ No newline at end of file