Class: Spree::PostsController

Inherits:
StoreController
  • Object
show all
Defined in:
app/controllers/spree/posts_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



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

def index
  @current_page = current_theme.pages.find_by!(type: 'Spree::Pages::PostList')

  scope = current_store.posts.published
  scope = scope.tagged_with(@tag.name) if @tag.present?
  scope = scope.where(post_category_id: @category.id) if @category.present?

  sorted_posts = scope.order(published_at: :desc)
  @posts = paginate_collection(sorted_posts, limit: 20)
end


32
33
34
35
36
# File 'app/controllers/spree/posts_controller.rb', line 32

def related_products
  @post = Spree::Post.friendly.find(params[:id])
  current_page = current_theme.pages.find_by!(type: 'Spree::Pages::Post')
  @section = current_page.sections.find_by!(id: params[:section_id], type: 'Spree::PageSections::RelatedProducts')
end

#showObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/spree/posts_controller.rb', line 19

def show
  if params[:preview_id].present?
    preview_post = current_store.posts.friendly.find(params[:id])
    raise ActiveRecord::RecordNotFound if preview_post.id.to_s != params[:preview_id]

    @post ||= preview_post
  else
    @post = current_store.posts.friendly.published.find(params[:id])
  end

  @current_page = current_theme.pages.find_by!(type: 'Spree::Pages::Post')
end