Skip to content

Commit

Permalink
#110: edit as profile, use find_coach for admin accessibility of coac…
Browse files Browse the repository at this point in the history
…h profile
  • Loading branch information
magicjascha committed Apr 15, 2019
1 parent dea5b17 commit e548a9b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 21 deletions.
40 changes: 27 additions & 13 deletions app/controllers/coaches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions app/views/coaches/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<h1>Your coach account</h1>
<%= link_to("View Public Profile", coach_path(@coach)) %>
<%= form_for(@coach, html: {class: "grey"}, method: :put) do |f| %>
<%= render 'shared/coachform', :f => f %>
<div class='button'>
<%= f.submit "Submit", class: 'commit', type: 'submit' %>
</div>
<% end %>
19 changes: 15 additions & 4 deletions app/views/coaches/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
<h1>Your coach account</h1>
<%= form_for @coach, html: {class: "grey"} do |f| %>
<%= render 'shared/coachform', :f => f %>
<% end %>
<h1>Coach <%= @coach.name %></h1>
<table>
<tr>
<td>Female</td>
<td><%= @coach.female %></td>
</tr>
<tr>
<td>gives talks in German</td>
<td><%= @coach.language_de %></td>
</tr>
<tr>
<td>gives talks in English</td>
<td><%= @coach.language_en %></td>
</tr>
</table>
10 changes: 6 additions & 4 deletions app/views/layouts/coach.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
<nav class="top-menu">
<ul>
<li style="float:right"><%= link_to "Sign out", sign_out_path, method: :delete %></li>
<li style="float:right"><%= link_to_active "Profile", coach_path(@coach) %></li>
<li> Logged in as <%= @coach.user.email %> </li>
<li style="float:right"><%= link_to_active "Profile", edit_coach_path(current_user.coach) %></li>
<li style="float:right"><%= link_to_active "Events", events_coaches_path %></li>
<li> Logged in as <%= current_user.email %> </li>
</ul>
</nav>
<%= yield %>
<footer>
<ul>
<li style="float:right"><%= link_to "Sign out", sign_out_path, method: :delete %></li>
<li style="float:right"><%= link_to_active "Profile", coach_path(@coach) %></li>
<li> Logged in as <%= @coach.user.email %> </li>
<li style="float:right"><%= link_to_active "Profile", edit_coach_path(current_user.coach) %></li>
<li style="float:right"><%= link_to_active "Events", events_coaches_path %></li>
<li> Logged in as <%= current_user.email %> </li>
</ul>
</footer>
<% end %>

0 comments on commit e548a9b

Please sign in to comment.