Class: LoyalCore::Ajax::RatingTracksController

Inherits:
LoyalCore::AjaxController show all
Defined in:
app/controllers/loyal_core/ajax/rating_tracks_controller.rb

Instance Method Summary collapse

Instance Method Details

#downObject



10
11
12
# File 'app/controllers/loyal_core/ajax/rating_tracks_controller.rb', line 10

def down
  down_or_up :down
end

#down_or_up(action) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/loyal_core/ajax/rating_tracks_controller.rb', line 14

def down_or_up(action)
  target_clazz = ::LoyalCore.config.clazz_alias[params[:target_type]]

  result = {}

  if target_clazz && (target_clazz = target_clazz.constantize)
    target = target_clazz.find_by_uuid(params[:target_id])

    if target
      result = { 
        :code        => target.send(:"#{action}_rating_by!", current_user),
        :action      => action,
        :up_rating   => target.up_rating,
        :down_rating => target.down_rating
      }
    end
  end

  render :json => {
    :response => {
      :status => 200,
      :code   => :success
    },
    :result => result
  }
end

#upObject



6
7
8
# File 'app/controllers/loyal_core/ajax/rating_tracks_controller.rb', line 6

def up
  down_or_up :up
end