Class: SearchesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/searches_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



14
15
16
17
18
19
20
# File 'app/controllers/searches_controller.rb', line 14

def create
  authorize! :create, Search
  @search = Search.new(params[:search])
  @search.organization_id = current_user.current_organization.id
  @search.save!
  redirect_to @search
end

#newObject



6
7
8
9
10
11
12
# File 'app/controllers/searches_controller.rb', line 6

def new
  authorize! :view, Search
  @search = Search.new(params[:search])
  @membership_types = current_user.current_organization.membership_types.all
  @pass_types       = current_user.current_organization.pass_types.all
  prepare_form
end

#showObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/searches_controller.rb', line 22

def show
  @search = Search.find(params[:id])
  authorize! :view, @search
  @segment = Segment.new
  @membership_types = current_user.current_organization.membership_types.all
  @pass_types       = current_user.current_organization.pass_types.all
  session[:return_to] ||= request.referer # Record the current page, in case creating a list segment fails.
  prepare_form
  prepare_people
  respond_to do |format|
    format.html { @people = @people.paginate(:page => params[:page], :per_page => (params[:per_page] || 20)) }
    format.csv  { render :csv => Person.where(:id => @people.collect(&:id)).includes(:phones, :address, :tags).order('lower(people.last_name)'), :filename => "#{@search.id}-#{DateTime.now.strftime("%m-%d-%y")}" }
  end
end

#tagObject



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

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