Class: MailManager::ContactsController

Inherits:
BaseController show all
Includes:
DeleteableActions
Defined in:
app/controllers/mail_manager/contacts_controller.rb

Instance Method Summary collapse

Methods included from DeleteableActions

#delete, #undelete

Methods inherited from BaseController

#site_url, #title, #use_show_for_resources?

Instance Method Details

#createObject



43
44
45
46
47
48
49
50
51
# File 'app/controllers/mail_manager/contacts_controller.rb', line 43

def create
  @contact = Contact.new(params[:contact])
  if @contact.save
    flash[:notice] = 'Contact was successfully created.'
    redirect_to(mail_manager.contacts_path)
  else
    render :action => "new"
  end
end

#destroyObject



63
64
65
66
67
# File 'app/controllers/mail_manager/contacts_controller.rb', line 63

def destroy
  find_contact
  @contact.delete
  redirect_to(mail_manager.contacts_url)
end

#editObject



39
40
41
# File 'app/controllers/mail_manager/contacts_controller.rb', line 39

def edit
  find_contact
end

#indexObject



29
30
31
32
33
# File 'app/controllers/mail_manager/contacts_controller.rb', line 29

def index
  @mailing_list = MailingList.find_by_id(params[:mailing_list_id])
  params[:status] ||= 'active'
  @contacts = Contact.search(params).paginate(:page => params[:page], :per_page => params[:per_page])
end

#newObject



35
36
37
# File 'app/controllers/mail_manager/contacts_controller.rb', line 35

def new
  @contact = Contact.new
end

#send_one_off_messageObject



21
22
23
24
25
26
27
# File 'app/controllers/mail_manager/contacts_controller.rb', line 21

def send_one_off_message
  @contact = Contact.find(params[:id])
  @mailing = Mailing.find(params[:mailing_id])
  @mailing.send_one_off_message(@contact)
  flash[:info] = "Test message sent to #{@contact.email_address_with_name}"
  redirect_to mail_manager.contacts_path
end

#subscribeObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/mail_manager/contacts_controller.rb', line 6

def subscribe
  if params[:contact].present? and params[:contact][:email_address].present?
    @contact = MailManager::Contact.find_by_email_address(params[:contact][:email_address])
    @contact = MailManager::Contact.new if @contact.nil?
    @contact.update_attributes(params[:contact])
    #check to see what list we subscribed to, if Austin local redirect, if San Antonio, redirect to their thank you page
  end

  if params[:redirect_url].present? #check to see if it came from SA
    redirect_to params[:redirect_url]
  else
    redirect_to mail_manager.thank_you_path #uncomment after testing...
  end
end

#updateObject



53
54
55
56
57
58
59
60
61
# File 'app/controllers/mail_manager/contacts_controller.rb', line 53

def update
  find_contact
  if @contact.update_attributes(params[:contact])
    flash[:notice] = 'Contact was successfully updated.'
    redirect_to(mail_manager.contacts_path)
  else
    render :action => "edit"
  end
end