Class: RestaurantCpt::Cell::CustomerRootPage
- Inherits:
-
Object
- Object
- RestaurantCpt::Cell::CustomerRootPage
- Defined in:
- app/concepts/restaurant_cpt/cell/customer_root_page.rb
Overview
Used by customer root path controller
Instance Attribute Summary collapse
-
#default_page ⇒ Object
Returns the value of attribute default_page.
-
#per_page ⇒ Object
Returns the value of attribute per_page.
Instance Method Summary collapse
- #collection ⇒ Object
- #initial_data ⇒ Object
-
#initialize(options = {}) ⇒ CustomerRootPage
constructor
A new instance of CustomerRootPage.
- #next_restaurants(page: nil) ⇒ Object
- #render(resources) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ CustomerRootPage
Returns a new instance of CustomerRootPage.
10 11 12 13 |
# File 'app/concepts/restaurant_cpt/cell/customer_root_page.rb', line 10 def initialize( = {}) self.default_page = .fetch(:page, 2) self.per_page = .fetch(:per_page, 15) end |
Instance Attribute Details
#default_page ⇒ Object
Returns the value of attribute default_page.
7 8 9 |
# File 'app/concepts/restaurant_cpt/cell/customer_root_page.rb', line 7 def default_page @default_page end |
#per_page ⇒ Object
Returns the value of attribute per_page.
7 8 9 |
# File 'app/concepts/restaurant_cpt/cell/customer_root_page.rb', line 7 def per_page @per_page end |
Instance Method Details
#collection ⇒ Object
24 25 26 27 28 29 |
# File 'app/concepts/restaurant_cpt/cell/customer_root_page.rb', line 24 def collection @collection ||= Restaurant.includes(:translations) .active .not_expired .order('rank ASC') end |
#initial_data ⇒ Object
15 16 17 |
# File 'app/concepts/restaurant_cpt/cell/customer_root_page.rb', line 15 def initial_data render collection.page(1).per(per_page) end |
#next_restaurants(page: nil) ⇒ Object
19 20 21 22 |
# File 'app/concepts/restaurant_cpt/cell/customer_root_page.rb', line 19 def next_restaurants(page: nil) pp = page || default_page render(collection.page(pp).per(per_page)) end |
#render(resources) ⇒ Object
31 32 33 34 |
# File 'app/concepts/restaurant_cpt/cell/customer_root_page.rb', line 31 def render(resources) ActiveModelSerializers::SerializableResource.new resources, each_serializer: Websites::RestaurantSliderSerializer end |