Module: Greedo::GridHelper

Defined in:
lib/greedo/grid_helper.rb

Defined Under Namespace

Classes: Grid

Instance Method Summary collapse

Instance Method Details

#greedo(scope, param_name: :page, page: params.fetch(param_name) { 1 }.to_i, per_page: nil, path_params: {}, order: , order_by: , &block) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/greedo/grid_helper.rb', line 158

def greedo(scope,
           param_name: :page,
           page: params.fetch(param_name) { 1 }.to_i,
           per_page: nil,
           path_params: {},
           order: params[:order],
           order_by: params[:order_by],
           &block)
  grid = Grid.new(view_context: self,
                  order: order,
                  order_by: order_by,
                  path_params: path_params)
  grid.configure(&block)
  grid.paginator = Paginator.build(scope,
                                   page: page,
                                   per_page: (params[:per_page] || per_page || 20).to_i,
                                   order_by: grid.ordered_by)
  render partial: "greedo/grid", locals: {grid: grid,
                                          param_name: param_name,
                                          path_params: path_params}
end