Class: Mg::RecordsController

Inherits:
Mg
  • Object
show all
Defined in:
lib/mountain-goat/controllers/mg/records_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject

GET /mg/records GET /mg/goals/:goal_id/records



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/mountain-goat/controllers/mg/records_controller.rb', line 6

def index
  @page = !params[:page].nil? ? params[:page].to_i : 1
  @goal = Mg::Goal.find(params[:goal_id]) if !params[:goal_id].nil?
 
  if @goal
    @records = @goal.mg_records.find(:all, :conditions => { }, :order => "created_at DESC", :limit => 100, :offset => ( @page - 1 ) * 100 )
  else
    @records = Mg::Record.find(:all, :conditions => { }, :order => "created_at DESC", :limit => 100, :offset => ( @page - 1 ) * 100 )
  end
  
  respond_to do |format|
    format.html { }
  end
end

#new_recordsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mountain-goat/controllers/mg/records_controller.rb', line 21

def new_records
  recent_record = params[:recent_record].to_i
  goal = Mg::Goal.find(params[:goal_id].to_i) unless params[:goal_id].blank?
  
  if goal
    @records = goal.mg_records.find(:all, :conditions => [ 'id > ?', recent_record ], :order => "id DESC" )
  else
    @records = Mg::Record.find(:all, :conditions => [ 'id > ?', recent_record ], :order => "id DESC" )
  end
  
  if @records.count > 0
    render :json => { :success => true,
                    :result => render_to_string(:partial => 'mg/records/records', :locals => { :records => @records } ),
                    :recent_record_id => @records.first.id }
  else
    render :json => { :success => false }
  end
  
end

#showObject

GET /mg/records/:id



42
43
44
# File 'lib/mountain-goat/controllers/mg/records_controller.rb', line 42

def show
  @record = Mg::Record.find(params[:id])
end