Sha256: 44c6d03ad51f70e6138076ad2c8eecc30d11bf9af283a6cd0f076ffcc43f77da

Contents?: true

Size: 876 Bytes

Versions: 8

Compression:

Stored size: 876 Bytes

Contents

class FavoritesController < BaseController
  before_filter :login_required, :only => [:destroy]
  before_filter :find_user, :only => [:show, :index]

  cache_sweeper :favorite_sweeper, :only => [:create, :destroy]  
  
  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
  
  def destroy
    @favorite = current_user.favorites.find(params[:id])
    @favorite.destroy
    
    respond_to do |format|
      format.js
    end    
  end
  
  def show
    @favorite = @user.favorites.find(params[:id])
  end
  
  def index  
    @favorites = Favorite.recent.by_user(@user).page(params[:page])
  end
  
  
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
community_engine-2.3.2 app/controllers/favorites_controller.rb
community_engine-2.3.1 app/controllers/favorites_controller.rb
community_engine-2.3.0 app/controllers/favorites_controller.rb
community_engine-2.1.0 app/controllers/favorites_controller.rb
community_engine-2.0.0 app/controllers/favorites_controller.rb
community_engine-2.0.0.beta3 app/controllers/favorites_controller.rb
community_engine-2.0.0.beta2 app/controllers/favorites_controller.rb
community_engine-2.0.0.beta1 app/controllers/favorites_controller.rb