| 1 | class PagesController < ApplicationController |
| 2 | def what_is_this |
| 3 | meta_tags 'what_is_this' |
| 4 | what_are_these |
| 5 | |
| 6 | # The page content itself |
| 7 | @page = Page |
| 8 | .select(:page_content, :title, :locale) |
| 9 | .where(category: :about, page_slug: 'what-is-this', locale: [I18n.locale, I18n.default_locale]) |
| 10 | .last |
| 11 | end |
| 12 | |
| 13 | def what_is_this_detail |
| 14 | slug = params[:slug] |
| 15 | @page = Page |
| 16 | .select(:page_content, :title, :locale) |
| 17 | .where(category: :what_is_this, page_slug: slug, locale: [I18n.locale, I18n.default_locale]) |
| 18 | .last |
| 19 | if @page.nil? |
| 20 | logger.info "Page not found: #{slug}" |
| 21 | return redirect_to what_is_this_path |
| 22 | end |
| 23 | |
| 24 | render_detail |
| 25 | end |
| 26 | |
| 27 | private |
| 28 | |
| 29 | def what_are_these |
| 30 | # List of what_is_this |
| 31 | @what_are_these = Page |
| 32 | .select(:page_content, :title, :page_slug) |
| 33 | .where(category: :what_is_this, locale: [I18n.locale, I18n.default_locale]) |
| 34 | end |
| 35 | |
| 36 | def meta_tags(home) |
| 37 | meta = Meta |
| 38 | .select(:title, :description) |
| 39 | .where(home: home, locale: [I18n.locale, I18n.default_locale]) |
| 40 | .last |
| 41 | @meta_title = meta.title if meta |
| 42 | @meta_description = meta.description if meta |
| 43 | @meta_url = request.url |
| 44 | end |
| 45 | |
| 46 | def render_detail |
| 47 | meta_tags 'what_is_this_detail' |
| 48 | what_are_these |
| 49 | |
| 50 | # Override meta title and meta description |
| 51 | @meta_title = @page.title |
| 52 | @meta_description = @page.page_content[0..100] |
| 53 | |
| 54 | render 'what_is_this' |
| 55 | end |
| 56 | end |