Sha256: 6d485883e27c13251f430a7774afb3f5ce7b02b143a98f949f4164ae8773ca89

Contents?: true

Size: 1.72 KB

Versions: 14

Compression:

Stored size: 1.72 KB

Contents

class SearchesController < ApplicationController

  before_filter :load_discount_codes
  before_filter :load_tags, :only => [:new, :show]

  def new
    authorize! :view, Search
    @search = Search.new(params[:search])
    @membership_types = MembershipType.all
    prepare_search_and_people
  end

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

  def show
    @search = Search.find(params[:id])
    authorize! :view, @search
    @segment = Segment.new
    @membership_types = MembershipType.all
    session[:return_to] ||= request.referer # Record the current page, in case creating a list segment fails.
    prepare_search_and_people
    respond_to do |format|
     format.html
     format.csv { render :csv => @search.people, :filename => "#{@search.id}-#{DateTime.now.strftime("%m-%d-%y")}" }
   end
  end

  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

  private

    def prepare_search_and_people
      @event_options = Event.options_for_select_by_organization(@current_user.current_organization)
      @people = @search.people
      @people = @people.paginate(:page => params[:page], :per_page => 20)
    end

    def load_discount_codes
      @discount_codes = Discount.where(:organization_id => current_user.current_organization).all.map(&:code)
      @discount_codes << Discount::ALL_DISCOUNTS_STRING
      @discount_codes_string = "\"" + @discount_codes.join("\",\"") + "\""
    end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
artfully_ose-1.2.0.pre.15 app/controllers/searches_controller.rb
artfully_ose-1.2.0.pre.12 app/controllers/searches_controller.rb
artfully_ose-1.2.0.pre.11 app/controllers/searches_controller.rb
artfully_ose-1.2.0.pre.10 app/controllers/searches_controller.rb
artfully_ose-1.2.0.pre.9 app/controllers/searches_controller.rb
artfully_ose-1.2.0.pre.8 app/controllers/searches_controller.rb
artfully_ose-1.2.0.pre.7 app/controllers/searches_controller.rb
artfully_ose-1.2.0.pre.6 app/controllers/searches_controller.rb
artfully_ose-1.2.0.pre.5 app/controllers/searches_controller.rb
artfully_ose-1.2.0.pre.4 app/controllers/searches_controller.rb
artfully_ose-1.2.0.pre.3 app/controllers/searches_controller.rb
artfully_ose-1.2.0.pre.2 app/controllers/searches_controller.rb
artfully_ose-1.2.0.pre.1 app/controllers/searches_controller.rb
artfully_ose-1.2.0.pre app/controllers/searches_controller.rb