Class: Spree::PostsController

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

Instance Method Summary collapse

Methods inherited from StoreController

#current_taxon, #default_products_sort, #permitted_products_params, #products_filters_params, #render_404_if_store_not_exists, #store_filter_names, #store_filter_names_hash

Methods included from AnalyticsHelper

#analytics_event_handlers, #track_event, #unsupported_event?, #visitor_id

Methods included from WishlistHelper

#current_wishlist

Methods included from PasswordProtected

#redirect_to_password

Methods included from StorefrontHelper

#as_aspect_ratio, #page_description, #page_image, #paths_equal?, #render_storefront_partials, #show_account_pane?, #svg_country_icon, #tailwind_classes_for

Methods included from ThemeConcern

#default_url_options, #set_theme_view_paths

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 = sorted_posts.page(params[:page]).per(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