Class: MembershipTypesController

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

Instance Method Summary collapse

Instance Method Details

#createObject



25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/membership_types_controller.rb', line 25

def create
  @membership_type = Kernel.const_get(params[:membership_type][:type].camelize).new(params[:membership_type])
  @membership_type.organization = current_organization
  unless @membership_type.save
    flash[:error] = @membership_type.errors.full_messages.to_sentence
    # @membership_type = Kernel.const_get(params[:membership_type][:type].camelize).new
    render "new" and return
  end
  redirect_to membership_types_path
end

#editObject



36
37
38
# File 'app/controllers/membership_types_controller.rb', line 36

def edit
  @membership_type = MembershipType.find(params[:id])
end

#indexObject



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

def index
  @membership_types = current_organization.membership_types.paginate(:page => params[:page], :per_page => 50)

  respond_to do |format|
    format.html

    format.csv do
      @filename = 'membership_types.csv'
      @csv_string = @membership_types.to_comma
      send_data @csv_string, :filename => @filename, :type => 'text/csv', :disposition => 'attachment'
    end
  end
end

#newObject



18
19
20
21
22
23
# File 'app/controllers/membership_types_controller.rb', line 18

def new
  with_type_selected do
    @membership_type = Kernel.const_get(params[:type].camelize).new
    @membership_type.hide_fee = true
  end
end

#updateObject



40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/membership_types_controller.rb', line 40

def update
  @membership_type = MembershipType.find(params[:id])
  
  if @membership_type.update_attributes(params[:membership_type])
    flash[:notice] = "Your changes have been saved"
    redirect_to membership_types_path
  else
    flash[:error] = @membership_type.errors.full_messages.to_sentence
    render "edit" and return
  end
end