Class: MembershipCompsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/membership_comps_controller.rb', line 26

def create
  @membership_comp = from_params(params)
  if params[:membership_comp][:confirm].present?
    @membership_comp.benefactor = current_user
    @membership_comp.award
    render 'create' and return
  else
    unless params[:membership_comp][:membership_type].present?
      flash[:error] = "Please select a membership type"
      redirect_to :back and return
    end

    @number_without_emails  =  @membership_comp.people.select{ |person| person.email.blank? }.length
    @number_of_companies    =  @membership_comp.people.select{ |person| person.company? }.length
    @email_preview          =  generate_invitation_preview_for(@membership_comp)
    if !@membership_comp.valid?
      flash[:error] = @membership_comp.errors.full_messages.to_sentence
      redirect_to :back and return 
    end
    render "confirm" and return
  end
end

#indexObject



20
21
22
23
24
# File 'app/controllers/membership_comps_controller.rb', line 20

def index
  @membership_comp = MembershipComp.new
  @membership_comp.membership_type = current_user.current_organization.membership_types.first
  render "create" and return
end

#newObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/membership_comps_controller.rb', line 4

def new
  @membership_types = current_organization.membership_types.all
  @membership_types_hash = {}
  @membership_types.each {|mt| @membership_types_hash[mt.id] = {:allow_multiple_memberships => mt.allow_multiple_memberships?,:formatted_ends_at => I18n.l(mt.ends_at, :format => :date_for_input)}}

  @membership_comp = MembershipComp.new
  @membership_comp.membership_type             ||= @membership_types.first
  @membership_comp.ends_at                     ||= I18n.l(@membership_types.first.ends_at, :format => :date_for_input)
  @membership_comp.send_email                  ||= true
  @membership_comp.number_of_memberships       ||= 1
  @membership_comp.person_id                    = params[:person_id]
  @membership_comp.segment_id                    = params[:segment_id]
  @membership_comp.search_id                    = params[:search_id]
  @membership_comp.people = find_people
end