Created
May 11, 2009 23:20
-
-
Save partydrone/110233 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
<% error_handling_form_for @article do |f| -%> | |
<%= f.text_field :title %> | |
<%= f.date_select :post_date, :order => [:month, :day, :year] %> | |
<%= f.text_area :body %> | |
<%= f.submit 'Submit' %> | |
<% end -%> |
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 ArticleSweeper < ActionController::Caching::Sweeper | |
observe Article | |
def after_save(article) | |
expire_cache(article) | |
end | |
def after_destroy(article) | |
expire_cache(article) | |
end | |
def expire_cache(article) | |
expire_page(formatted_ticker_articles_path(:rss)) | |
expire_page(article_path(article)) | |
end | |
end |
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 ArticlesController < ApplicationController | |
before_filter { |c| c.send :set_page_title, ['News'] } | |
before_filter :login_required, :except => [:index, :ticker, :show] | |
caches_page :ticker, :show | |
cache_sweeper :article_sweeper, :only => [:create, :update, :destroy] | |
# GET /articles | |
def index | |
@articles = Article.current | |
end | |
# GET /articles/ticker | |
def ticker | |
@articles = Article.current(:limit => 5) | |
respond_to do |format| | |
format.rss # /articles/ticker.rss | |
end | |
end | |
# GET /articles/:id | |
def show | |
@article = Article.find(params[:id]) | |
@page_title << @article.title | |
end | |
# GET /articles/new | |
def new | |
@article = Article.new | |
end | |
# GET /articles/:id/edit | |
def edit | |
@article = Article.find(params[:id]) | |
end | |
# POST /articles | |
def create | |
@article = Article.new(params[:article]) | |
if @article.save | |
flash[:notice] = "<em>#{@article.title}</em> was successfully created." | |
redirect_to articles_path | |
else | |
render :action => 'new' | |
end | |
end | |
# PUT /articles/:id | |
def update | |
@article = Article.find(params[:id]) | |
if @article.update_attributes(params[:article]) | |
flash[:notice] = "<em>#{@article.title}</em> was successfully updated." | |
redirect_to articles_path | |
else | |
render :action => 'edit' | |
end | |
end | |
# DELETE /articles/:id | |
def destroy | |
@article = Article.find(params[:id]) | |
@article.destroy | |
redirect_to articles_path | |
end | |
end |
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
<h1 id="page_title">New Article</h1> | |
<%= render :partial => 'form' %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment