Class: FavoritesController

Inherits:
BaseController show all
Defined in:
app/controllers/favorites_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#advertise, #cache_action?, #css_help, #footer_content, #homepage_features, #plaxo, #rss_site_index, #site_index

Methods included from LocalizedApplication

#get_matching_ui_locale, #get_sorted_langs_from_accept_header, #get_valid_lang_from_accept_header, #set_locale

Methods included from AuthenticatedSystem

#login_by_token, #update_last_seen_at

Instance Method Details

#createObject



7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/favorites_controller.rb', line 7

def create
  @favoritable = params[:favoritable_type].classify.constantize.find(params[:favoritable_id])
  @favorite = Favorite.new(:ip_address => request.remote_ip, :favoritable => @favoritable )
  @favorite.user = current_user || nil
  @favorite.save
  
  respond_to do |format|
    format.js
  end
end

#destroyObject



18
19
20
21
22
23
24
25
# File 'app/controllers/favorites_controller.rb', line 18

def destroy
  @favorite = current_user.favorites.find(params[:id])
  @favorite.destroy
  
  respond_to do |format|
    format.js
  end    
end

#indexObject



31
32
33
# File 'app/controllers/favorites_controller.rb', line 31

def index  
  @favorites = Favorite.recent.by_user(@user).page(params[:page])
end

#showObject



27
28
29
# File 'app/controllers/favorites_controller.rb', line 27

def show
  @favorite = @user.favorites.find(params[:id])
end