Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

join and quit groups

  • Loading branch information...
commit 27d2d90cf56ef9fb245e2e2b29fab16eb29e7d37 1 parent 6ef530f
mcansky authored
View
14 app/controllers/groups_controller.rb
@@ -24,6 +24,20 @@ def new
@group = Group.new
end
+ def join
+ group = Group.find(params[:id])
+ group.users << current_user unless group.users.include?(current_user)
+ group.save
+ redirect_to :action => :show, :id => group.id
+ end
+
+ def quit
+ group = Group.find(params[:id])
+ group.users.delete(current_user) if group.users.include?(current_user)
+ group.save
+ redirect_to :action => :show, :id => group.id
+ end
+
def create
@group = Group.new
@group.name = params[:group][:name]
View
1  app/controllers/posts_controller.rb
@@ -127,6 +127,7 @@ def create
end
end
elsif params[:id]
+ incomplete = false
# clone
to_clone = Bookmark.find(params[:id])
if to_clone == nil
View
6 app/views/application/_sidebar.haml
@@ -19,7 +19,8 @@
%h4.sidebar
Groups
- = render "application/sidebar_groups", :groups => current_user.groups
+ - groups = @user.groups + @user.owned_groups
+ = render "application/sidebar_groups", :groups => groups
%div.side_bar_tags
%h4.sidebar
@@ -43,7 +44,8 @@
%h4.sidebar
Groups
= link_to "+", {:controller => "/groups", :action => :new}, {:class => "sidebar_new_group"}
- = render "application/sidebar_groups", :groups => current_user.groups
+ - groups = current_user.groups + current_user.owned_groups
+ = render "application/sidebar_groups", :groups => groups
%div.side_bar_tags
%h4.sidebar
View
2  app/views/application/_sidebar_groups.haml
@@ -1,2 +1,2 @@
-- groups.each do |group|
+- groups.uniq.each do |group|
= link_to group.name, {:controller => :groups, :action => :show, :id => group.id}, {:class => "title"}
View
8 app/views/groups/show.haml
@@ -2,6 +2,14 @@
%h2
= @group.name
group
+ %span.follow
+ - if @group.owner == current_user
+ = link_to 'e', {:controller => "groups", :action => "edit", :id => @group.id}, {:class => "edit", :title => "edit"}
+ = link_to 'd!', @group, {:confirm => "Deleting, You sure ?", :method => :delete, :title => "destroy"}
+ - elsif @group.users.include?(current_user)
+ = link_to "q", {:controller => :groups, :action => :quit, :id => @group.id}, {:confirm => "Quitting the group, You sure ?", :method => :delete, :title => "quit"}
+ - else
+ = link_to "j", {:controller => :groups, :action => :join, :id => @group.id}, {:method => :post, :title => "join"}
%p
Owned by :
View
5 config/routes.rb
@@ -22,7 +22,8 @@
# groups
resources :groups
- match 'groups/join', :to => 'groups#join', :via => [:delete, :post]
+ match 'groups/join/:id', :to => 'groups#join', :via => :post
+ match 'groups/quit/:id', :to => 'groups#quit', :via => :delete
# stats
match 'stats/', :to => 'stats#index', :via => :get
@@ -30,7 +31,7 @@
# follow
#match 'users/follow/:id', :to => 'users#follow', :via => [:delete, :post]
- match "users/follow/:id" => 'users#follow', :via => [:get, :post]
+ match "users/follow/:id" => 'users#follow', :via => [:get, :delete, :post]
# api
match 'v1/posts/all', :to => 'v1/posts#index'
Please sign in to comment.
Something went wrong with that request. Please try again.