Module: RecordSelect::Actions

Defined in:
lib/record_select/actions.rb

Instance Method Summary collapse

Instance Method Details

#browseObject

:method => :get params => [:page, :search]



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/record_select/actions.rb', line 5

def browse
  query = record_select_query
  @count = query.count if record_select_config.pagination?
  @count = @count.length if @count.is_a? Hash
  pager = ::Paginator.new(@count, record_select_config.per_page) do |offset, per_page|
    search = record_select_select ? query.select(record_select_select) : query
    search = search.limit(per_page).offset(offset) if record_select_config.pagination?
    search.includes(record_select_config.include).order(record_select_config.order_by).to_a
  end
  @page = pager.page(params[:page] || 1)

  respond_to do |wants|
    wants.html { render_record_select :partial => 'browse'}
    wants.js {
      if params[:update]
        render_record_select :template => 'browse'
      else
        render_record_select :partial => 'browse'
      end
    }
    wants.yaml {}
    wants.xml {}
    wants.json {}
  end
end

#selectObject

:method => :post params => [:id]



33
34
35
36
37
38
39
40
41
42
# File 'lib/record_select/actions.rb', line 33

def select
  klass = record_select_model
  record = klass.find(params[:id])
  if record_select_config.notify.is_a? Proc
    record_select_config.notify.call(record)
  elsif record_select_config.notify
    send(record_select_config.notify, record)
  end
  render :nothing => true
end