Skip to content

Commit

Permalink
you should probably be able to leave groups...
Browse files Browse the repository at this point in the history
  • Loading branch information
addc-heroku committed Oct 1, 2014
1 parent 80f4633 commit 34b98e7
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 13 deletions.
7 changes: 7 additions & 0 deletions app/controllers/user_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ def add_user_to_group
redirect_to group_path(group_to_add)
end

def leave_group
group_to_leave = params[:group_id]
current_user.groups.delete(group_to_leave)
flash[:notice] = "successfully left group"
redirect_to user_path(current_user)
end

private

def user_params
Expand Down
2 changes: 1 addition & 1 deletion app/views/application/_navigation.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
%li
= link_to group.name, group_path(group)
%li= link_to current_user.friendly_title, user_path(current_user)
%li= link_to "Log out", destroy_user_session_path(current_user), :method => :destroy
%li= link_to "Log out", destroy_user_session_path, :method => :destroy
1 change: 1 addition & 0 deletions app/views/user/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
- @user.groups.each do |group|
%li
= link_to group.name, group_path(group)
= link_to "(leave)", leave_group_path(group)

%p= link_to "Edit", edit_user_path(current_user)
12 changes: 0 additions & 12 deletions app/views/users/edit.html.haml

This file was deleted.

1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
resources :user, :groups

post 'users/add_user_to_group' => 'user#add_user_to_group', as: :add_user
get 'users/leave/:group_id' => 'user#leave_group', as: :leave_group
# Example of regular route:
# get 'products/:id' => 'catalog#view'

Expand Down

0 comments on commit 34b98e7

Please sign in to comment.