Skip to content

Instantly share code, notes, and snippets.

@stephencelis
Created March 2, 2009 15:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephencelis/72785 to your computer and use it in GitHub Desktop.
Save stephencelis/72785 to your computer and use it in GitHub Desktop.
class ArticlesController < ActionController::Base
helper_method :articles, :article
# render index, show, new, edit
def create
article.save!
redirect_to articles_path
end
def update
article.update_attributes! params[:article]
redirect_to articles_path
end
def destroy
article.destroy
redirect_to articles_path
end
private
def articles
@articles ||= Article.all
end
def article
@article ||= if params[:id]
Article.find params[:id]
else
Article.new params[:article]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment