Class: ArticlesController

Inherits:
ApplicationController show all
Defined in:
lib/app/controllers/articles_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/app/controllers/articles_controller.rb', line 20

def create
  @article = Article.new(params[:article])
  @article.user = @current_user
  
  if @article.save
    flash[:notice] = "Success: created article."
    redirect_to(article_permalink_url(@article))
  else
    render :action => 'new', :status => :unprocessable_entity
  end
end

#destroyObject



59
60
61
62
63
64
# File 'lib/app/controllers/articles_controller.rb', line 59

def destroy
  article = Article.find params[:id]
  article.destroy
  flash[:success] = "Article destroyed."
  redirect_to articles_url
end

#editObject



55
56
57
# File 'lib/app/controllers/articles_controller.rb', line 55

def edit
  @article = Article.find params[:id]
end

#indexObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/app/controllers/articles_controller.rb', line 3

def index
  respond_to do |format|      
    format.html do
      @articles = Article.page_items params[:page]
    end
    
    format.atom do
      if feed_publisher_request?
        @articles = Article.feed_items
        render :layout => false
      else
        redirect_to feed_publisher_url
      end
    end
  end
end

#newObject



32
33
34
# File 'lib/app/controllers/articles_controller.rb', line 32

def new
  @article = Article.new
end

#showObject



36
37
38
39
40
41
42
# File 'lib/app/controllers/articles_controller.rb', line 36

def show
  begin
    @article = Article.find_by_permalink params
  rescue
    @article = Article.find params[:id]
  end
end

#updateObject



44
45
46
47
48
49
50
51
52
53
# File 'lib/app/controllers/articles_controller.rb', line 44

def update
  @article = Article.find params[:id]
  
  if @article.update_attributes(params[:article])
    flash[:notice] = "Article updated."
    redirect_to article_url(@article)
  else
    render :action => 'edit', :status => :unprocessable_entity
  end
end