Class: Rtcl::ArticlesController

Inherits:
ApplicationController show all
Includes:
Pagy::Backend
Defined in:
app/controllers/rtcl/articles_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#set_page_title

Instance Method Details

#createObject



30
31
32
33
34
35
36
37
# File 'app/controllers/rtcl/articles_controller.rb', line 30

def create
  @article = Article.new(article_params.merge(author: current_user))
  if @article.save
    redirect_to @article
  else
    render :new
  end
end

#destroyObject



47
48
49
50
# File 'app/controllers/rtcl/articles_controller.rb', line 47

def destroy
  @article.discard!
  redirect_to articles_path
end

#editObject



27
28
# File 'app/controllers/rtcl/articles_controller.rb', line 27

def edit
end

#indexObject



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

def index
  if params[:tag]
    @paginator, @articles = pagy(Article.tagged_with(params[:tag]).accessible_by(current_ability).latest, items: 8)
  else
    @paginator, @articles = pagy(Article.kept.accessible_by(current_ability).latest, items: 8)
  end
  respond_to do |format|
    format.html
    format.rss { render :layout => false }
  end
end

#newObject



23
24
25
# File 'app/controllers/rtcl/articles_controller.rb', line 23

def new
  @article = Article.new
end

#showObject



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

def show
end

#updateObject



39
40
41
42
43
44
45
# File 'app/controllers/rtcl/articles_controller.rb', line 39

def update
  if @article.update(article_params)
    render :show
  else
    render :edit
  end
end