/
accounts.rb
47 lines (41 loc) · 1.11 KB
/
accounts.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Admin.controllers :accounts do
get :index do
@accounts = Account.all
render 'accounts/index'
end
get :new do
@account = Account.new
render 'accounts/new'
end
post :create do
@account = Account.new(params[:account])
if @account.save
flash[:notice] = 'Account was successfully created.'
redirect url(:accounts, :edit, :id => @account.id)
else
render 'accounts/new'
end
end
get :edit, :with => :id do
@account = Account.find(params[:id])
render 'accounts/edit'
end
put :update, :with => :id do
@account = Account.find(params[:id])
if @account.update_attributes(params[:account])
flash[:notice] = 'Account was successfully updated.'
redirect url(:accounts, :edit, :id => @account.id)
else
render 'accounts/edit'
end
end
delete :destroy, :with => :id do
account = Account.find(params[:id])
if account != current_account && account.destroy
flash[:notice] = 'Account was successfully destroyed.'
else
flash[:error] = 'Unable to destroy Account!'
end
redirect url(:accounts, :index)
end
end