Class: Dust::ContactsController
Instance Method Summary
collapse
#not_authenticated, #permission_denied, #try_return_to_previous_page
Instance Method Details
#create ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
|
# File 'app/controllers/dust/contacts_controller.rb', line 18
def create
@page = Dust::Page.find(1)
@contact = Dust::Contact.new(params[:dust_contact])
if @contact.save
@contact.deliver_messages
flash[:notice] = "Successfully Sent Message."
redirect_to root_url
else
render :action => 'new', :layout => 'application'
end
end
|
#csv ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'app/controllers/dust/contacts_controller.rb', line 51
def csv
@contacts = Dust::Contact.order("created_at DESC")
if @contacts.empty?
flash[:error] = "There are no contact requests available."
redirect_to dust_contacts_path
else
csv_string = CSV.generate do |csv|
csv << ["Name", "Email", "message"]
@contacts.each do |contact|
csv << [contact['name'], contact['email'], contact['message']]
end
end
send_data(csv_string,
:type => 'text/csv; charset=utf-8; header=present',
:filename => "AllDust::Contacts#{Date.today}.csv"
)
end
end
|
#csv_import ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'app/controllers/dust/contacts_controller.rb', line 71
def csv_import
csv = CSV.new(params[:csv_import][:file])
csv.each do |row|
Dust::Contact.create(:name => row[0],
:email => row[1],
:message => row[2]
)
end
csv.close
flash[:notice] = "Successfully added some Dust::Contact(s)."
redirect_to contacts_path
rescue => exception
error = ERB::Util.h(exception.to_s) flash[:error] = "Error adding logs. (some #{error}). Please try again."
redirect_to contacts_path
end
|
#destroy ⇒ Object
44
45
46
47
48
49
|
# File 'app/controllers/dust/contacts_controller.rb', line 44
def destroy
@contact = Dust::Contact.find(params[:id])
@contact.destroy
flash[:notice] = "Successfully destroyed contact."
redirect_to dust_contacts_url
end
|
#edit ⇒ Object
30
31
32
|
# File 'app/controllers/dust/contacts_controller.rb', line 30
def edit
@contact = Dust::Contact.find(params[:id])
end
|
#index ⇒ Object
10
11
12
|
# File 'app/controllers/dust/contacts_controller.rb', line 10
def index
@contacts = Dust::Contact.page(params[:search], params[:page], params[:date])
end
|
#new ⇒ Object
14
15
16
|
# File 'app/controllers/dust/contacts_controller.rb', line 14
def new
@contact = Dust::Contact.new
end
|
#update ⇒ Object
34
35
36
37
38
39
40
41
42
|
# File 'app/controllers/dust/contacts_controller.rb', line 34
def update
@contact = Dust::Contact.find(params[:id])
if @contact.update_attributes(params[:dust_contact])
flash[:notice] = "Successfully updated contact."
redirect_to @contact
else
render :action => 'edit'
end
end
|