Class: Bongo::ArticlesController

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

Direct Known Subclasses

DraftsController

Instance Method Summary collapse

Instance Method Details

#createObject



33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/bongo/articles_controller.rb', line 33

def create
  @article = Article.new(article_params)
  authorize @article

  if @article.save
    redirect_to @article, notice: 'Article was successfully created.'
  else
    render :new
  end
end

#destroyObject



54
55
56
57
58
# File 'app/controllers/bongo/articles_controller.rb', line 54

def destroy
  authorize @article
  @article.destroy
  redirect_to articles_url, notice: 'Article was successfully destroyed.'
end

#editObject



29
30
31
# File 'app/controllers/bongo/articles_controller.rb', line 29

def edit
  authorize @article
end

#indexObject



9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/bongo/articles_controller.rb', line 9

def index
  @articles = policy_scope(Article).published.order(publish_at: :desc)
  respond_to do |format|
    format.html
    format.rss do
      @articles = @articles.published.order(publish_at: :desc)
      render layout: false
    end
  end
end

#newObject



24
25
26
27
# File 'app/controllers/bongo/articles_controller.rb', line 24

def new
  @article = Article.new
  authorize @article
end

#showObject



20
21
22
# File 'app/controllers/bongo/articles_controller.rb', line 20

def show
  authorize @article
end

#updateObject



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

def update
  authorize @article

  if @article.update(article_params)
    redirect_to @article, notice: 'Article was successfully updated.'
  else
    render :edit
  end
end