Skip to content
Extraits de code Groupes Projets
groups_controller.rb 1,7 ko
Newer Older
class GroupsController < ApplicationController
  before_filter :authenticate_user!

  respond_to :html
  respond_to :json, :only => :show

    @posts = current_user.visible_posts(:by_members_of => :all).paginate :page => params[:page], :order => 'created_at DESC'
    @group = current_user.group params[:group]
  end
  
  def new
    @group = Group.new
  end
  
  def destroy
    @group = Group.find_by_id params[:id]
    @group   = Group.find_by_id params[:id]
    @friends = @group.people
    @posts   = current_user.visible_posts( :by_members_of => @group ).paginate :order => 'created_at DESC'

    respond_with @group
maxwell's avatar
maxwell a validé
    @groups = current_user.groups
    @group = Group.find_by_id(params[:id])
    @group.update_attributes(params[:group])
    respond_with @group
Raphael's avatar
Raphael a validé
  def move_friends
    params[:moves].each{ |move|
      move = move[1]
      unless current_user.move_friend(move)
        flash[:error] = "Group editing failed for friend #{Person.find_by_id( move[:friend_id] ).real_name}."
        redirect_to Group.first, :action => "edit"
        return
      end
    }

    flash[:notice] = "Groups edited successfully."
    redirect_to Group.first, :action => "edit"
maxwell's avatar
maxwell a validé
  end
  def move_friend
    unless current_user.move_friend( :friend_id => params[:friend_id], :from => params[:from], :to => params[:to][:to]) 
      flash[:error] = "didn't work #{params.inspect}"
    end
    if group = Group.first(:id => params[:to][:to])
      redirect_to group 
    else
      redirect_to Person.first(:id => params[:friend_id])
    end
  end