Skip to content

Instantly share code, notes, and snippets.

@raws
Created February 23, 2010 07:43
Show Gist options
  • Save raws/311978 to your computer and use it in GitHub Desktop.
Save raws/311978 to your computer and use it in GitHub Desktop.
class CommandsController < ApplicationController
before_filter :authorize, :except => [ :index, :show ]
def index
@commands = Command.all(:order => "name")
end
def new
@command = Command.new(params[:command])
end
def create
@command = Command.new(params[:command])
@command.created_by = session["username"]
if @command.save
redirect_to url_for(@command)
else
render :action => "new"
end
end
def show
@command = Command.first(:name => params[:id])
render_404 unless @command
end
def edit
@command = Command.first(:name => params[:id])
render_404 unless @command
end
def update
command = Command.first(:name => params[:id])
if command
params["command"]["updated_by"] = session["username"]
command.update_attributes(params["command"])
command.save!
render :nothing => true
else
render_404
end
end
def destroy
command = Command.first(:name => params[:id])
if command
command.destroy
else
render_404
end
render :nothing => true if request.xhr?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment