Class: Mg::ConvertsController

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

Instance Method Summary collapse

Instance Method Details

#createObject

POST /converts POST /converts.xml



73
74
75
76
77
78
79
80
81
82
# File 'lib/mountain-goat/controllers/mg/converts_controller.rb', line 73

def create
  @convert = Mg::Convert.new(params[:convert])

  if @convert.save
    flash[:notice] = 'Convert was successfully created.'
    redirect_to mg_convert_url :id => @convert.id
  else
    render :action => "new"
  end
end

#destroyObject

DELETE /converts/1 DELETE /converts/1.xml



99
100
101
102
103
104
105
106
107
# File 'lib/mountain-goat/controllers/mg/converts_controller.rb', line 99

def destroy
  @convert = Mg::Convert.find(params[:id])
  @convert.destroy

  respond_to do |format|
    format.html { redirect_to mg_converts_url }
    format.xml  { head :ok }
  end
end

#editObject

GET /converts/1/edit



67
68
69
# File 'lib/mountain-goat/controllers/mg/converts_controller.rb', line 67

def edit
  @convert = Convert.find(params[:id])
end

#indexObject

GET /converts GET /converts.xml



6
7
8
9
10
11
12
13
# File 'lib/mountain-goat/controllers/mg/converts_controller.rb', line 6

def index
  @converts = Mg::Convert.all

  respond_to do |format|
    format.html # index.html.erb
    format.xml  { render :xml => @converts }
  end
end

#newObject

GET /converts/new GET /converts/new.xml



57
58
59
60
61
62
63
64
# File 'lib/mountain-goat/controllers/mg/converts_controller.rb', line 57

def new
  @convert = Mg::Convert.new

  respond_to do |format|
    format.html # new.html.erb
    format.xml  { render :xml => @convert }
  end
end

#showObject

GET /converts/1 GET /converts/1.xml



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/mountain-goat/controllers/mg/converts_controller.rb', line 17

def show
  @convert = Mg::Convert.find(params[:id])

  @results_per_day = []
  created_at = @convert.created_at
  running_date = Time.utc( created_at.year, created_at.month, created_at.day )
  
  while running_date < Time.zone.now
    @results_per_day.push({ :date => running_date.to_i * 1000, :val => @convert.rallies.find( :all, :conditions => { :created_at => running_date..(running_date + 60 * 60 * 24) } ).count })
    running_date += 60 * 60 * 24
  end
  
  @results_by_cmt = {}
  @results_by_cmt_titles = {}
  
  @convert.convert_meta_types.each do |cmt|
    @results_by_cmt[cmt.id] = []
    @results_by_cmt_titles[cmt.id] = {}
    i = 0
    cmt.meta.all(:select => "data, count(*) as count", :group => "data").each do |meta|
      next if meta.data.nil?
      if cmt.meta_type == 'cs_meta'
        @results_by_cmt[cmt.id].push( { :name => i, :val => meta.count } )
        @results_by_cmt_titles[cmt.id].merge!({ i => meta.data })
      else
        @results_by_cmt[cmt.id].push( { :name => meta.data, :val => meta.count } )
      end
      
      i += 1
    end
  end
  
  respond_to do |format|
    format.html # show.html.erb
    format.xml  { render :xml => @convert }
  end
end

#updateObject

PUT /converts/1 PUT /converts/1.xml



86
87
88
89
90
91
92
93
94
95
# File 'lib/mountain-goat/controllers/mg/converts_controller.rb', line 86

def update
  @convert = Mg::Convert.find(params[:id])

  if @convert.update_attributes(params[:convert])
    flash[:notice] = 'Convert was successfully updated.'
    redirect_to mg_convert_url :id => @convert.id
  else
    render :action => "edit"
  end
end