Skip to content

Instantly share code, notes, and snippets.

@achiurizo
Created April 29, 2010 03:14
Show Gist options
  • Save achiurizo/383069 to your computer and use it in GitHub Desktop.
Save achiurizo/383069 to your computer and use it in GitHub Desktop.
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 rescue false)
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.filter(:id => params[:id]).first
render 'accounts/edit'
end
put :update, :with => :id do
@account = Account.filter(:id =>params[:id]).first
if (@account.update(params[:account]) rescue false)
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.filter(:id => params[:id]).first
if account != current_account && account.destroy
flash[:notice] = 'Account was successfully destroyed.'
else
flash[:error] = 'Impossible destroy Account!'
end
redirect url(:accounts, :index)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment