Class: Lines::ArticlesController

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

Constant Summary collapse

KEYWORDS =
CONFIG[:keywords]
SITE_TITLE =
CONFIG[:title]

Instance Method Summary collapse

Instance Method Details

#indexObject

Lists all published articles. Responds to html and atom



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/lines/articles_controller.rb', line 16

def index
  respond_to do |format|
    format.html {
      @first_page = (params[:page] and params[:page].to_i > 0) ? false : true
      if params[:tag]
        @articles = Lines::Article.published.tagged_with(params[:tag]).page(params[:page].to_i)
      else
        @articles = Lines::Article.published.page(params[:page].to_i).padding(1)
      end
      
      if @articles.first_page?
        if @first_article = Article.published.first
          @first_article.teaser = nil unless @first_article.teaser.present?
        end
      end
      
      set_meta_tags title: SITE_TITLE,
                    description: CONFIG[:meta_description],
                    keywords: KEYWORDS,
                    open_graph: { title: SITE_TITLE,
                                    type: 'website',
                                    url: articles_url,
                                    site_name: SITE_TITLE,
                                    image: CONFIG[:og_logo]
                                  }

    }
    format.atom{
      @articles = Lines::Article.published
    }
  end
end

#showObject

Shows specific article



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/lines/articles_controller.rb', line 50

def show
  @first_page = true
  @article = Lines::Article.published.find(params[:id])
  @article.teaser = nil unless @article.teaser.present?
  meta_tags = { title: @article.title,
    type: 'article',
    url: url_for(@article),
    site_name: SITE_TITLE,
  }
  meta_tags[:image] = CONFIG[:host] + @article.image_url if @article.image_url.present?
  set_meta_tags title: @article.title,
                keywords: KEYWORDS + @article.tag_list.to_s,
                open_graph: meta_tags
  if request.path != article_path(@article)
    return redirect_to @article, status: :moved_permanently
  end

  @related_articles = Lines::Article.published.where('id != ?', @article.id).order('').limit(2)
end