Class: DmCms::BlogsController

Inherits:
ApplicationController show all
Includes:
ApplicationHelper, DmCore::RenderHelper
Defined in:
app/controllers/dm_cms/blogs_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject




15
16
17
18
19
20
21
22
23
# File 'app/controllers/dm_cms/blogs_controller.rb', line 15

def index
  redirect_to(index_url) and return if CmsBlog.count == 0
  @blogs        = CmsBlog.available_to_user(current_user)
  @posts        = CmsPost.where(cms_blog_id: @blogs.map(&:id)).includes(:cms_blog, :translations).published.order('published_on DESC').paginate page: page_number
  @recent_posts = CmsPost.where(cms_blog_id: @blogs.map(&:id)).includes(:cms_blog, :translations).published.order('published_on DESC').limit(5)
  content_for :page_title, I18n.t('cms.blog_header')
  
  render action: :show
end

#showObject




26
27
28
29
30
31
# File 'app/controllers/dm_cms/blogs_controller.rb', line 26

def show
  @blogs        = CmsBlog.available_to_user(current_user)
  @posts        = @blog.posts.includes(:cms_blog, :translations).published.order('published_on DESC').paginate :page => page_number
  @recent_posts = @blog.posts.includes(:cms_blog, :translations).published.order('published_on DESC').limit(5)
  content_for :page_title, (@blog ? @blog.title : I18n.t('cms.blog_header'))
end

#toggle_followObject




34
35
36
37
38
39
# File 'app/controllers/dm_cms/blogs_controller.rb', line 34

def toggle_follow
  @blog = CmsBlog.friendly.find(params[:cms_blog_id])
  authorize! :read, @blog
  @following = current_user.following.following?(@blog)
  @following ? current_user.following.stop_following(@blog) : current_user.following.follow(@blog)
end