Created
February 23, 2010 07:43
-
-
Save raws/311978 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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