Class: SegmentsController

Inherits:
ArtfullyOseController show all
Defined in:
app/controllers/segments_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/segments_controller.rb', line 19

def create
  authorize! :create, Segment
  @segment = current_organization.segments.build(params[:segment])
  if @segment.save
    redirect_to @segment
  else
    flash[:error] = "List segment could not be created. Please remember to type a name."
    redirect_to session[:return_to]
  end
end

#destroyObject



30
31
32
33
34
# File 'app/controllers/segments_controller.rb', line 30

def destroy
  authorize! :destroy, Segment
  current_organization.segments.find(params[:id]).destroy
  redirect_to segments_path
end

#indexObject



4
5
6
7
# File 'app/controllers/segments_controller.rb', line 4

def index
  authorize! :view, Segment
  @segments = current_organization.segments.paginate(:page => params[:page], :per_page => 10)
end

#showObject



9
10
11
12
13
14
15
16
17
# File 'app/controllers/segments_controller.rb', line 9

def show
  @segment = Segment.find(params[:id])
  authorize! :view, @segment
  @people = @segment.people
  respond_to do |format|
    format.html { @people = @people.paginate(:page => params[:page], :per_page => 20) }
    format.csv  { render :csv => Person.where(:id => @people.collect(&:id)).includes(:phones, :address, :tags).order('lower(people.last_name)'), :filename => "#{@segment.name}-#{DateTime.now.strftime("%m-%d-%y")}" }
  end
end

#tagObject



36
37
38
39
40
41
42
# File 'app/controllers/segments_controller.rb', line 36

def tag
  @segment = Segment.find(params[:id])
  authorize! :tag, Segment
  @segment.tag(params[:name])
  flash[:notice] = "We're tagging all the people in this list segment and we'll be done shortly.  Refresh this page in a minute or two."
  redirect_to @segment
end