class FollowingsController

OpenIrekia v4.0.0

Copyright 2009-2013 eFaber, S.L. Copyright 2009-2013 Ejie, S.A. Copyrigth 2009-2013 Dirección de Gobierno Abierto y Comunicación en Internet;

Gobernu Irekirako eta Interneteko Komunikaziorako Zuzendaritza; Lehendakaritza.
Gobierno Vasco – Eusko Jaurlaritza

Licencia con arreglo a la EUPL, Versión 1.1 o –en cuanto sean aprobadas por la Comisión Europea– versiones posteriores de la EUPL (la Licencia); Solo podrá usarse esta obra si se respeta la Licencia. Puede obtenerse una copia de la Licencia en: ec.europa.eu/idabc/eupl Salvo cuando lo exija la legislación aplicable o se acuerde por escrito, el programa distribuido con arreglo a la Licencia se distribuye TAL CUAL, SIN GARANTÍAS NI CONDICIONES DE NINGÚN TIPO, ni expresas ni implícitas. Véase la Licencia en el idioma concreto que rige los permisos y limitaciones que establece la Licencia

http://open.irekia.net, openirekia@efaber.net

Public Instance Methods

create() click to toggle source
# File app/controllers/followings_controller.rb, line 35
def create
  params[:following].merge!(:user_id => current_user.id)
  @following = Following.new(params[:following])
  @item = @following.followed
  if @following.save
    respond_to do |format|
      format.html {
        render :template => 'followings/update_all', :locals => {:item => @following.followed, :action => 'destroy'}, :layout => !request.xhr?                    
      }
      format.json {
        render :action => 'follow.json', :layout => false
      }
      format.floki { 
        render :action => 'follow.json', :layout => false
      }
    end  
  else
    respond_to do |format|
      format.html {
        @following=Following.find(:first, :conditions => params[:following])
        # render :json => t('followings.ya_existe').to_json, :status => 500
        render :partial => 'followings/destroy', :layout => false, :status => 500
      }
      format.json {
        @item = @following.followed
        render :action => 'follow.json', :layout => false
      }
      format.floki {
        @item = @following.followed
        render :action => 'follow.json', :layout => false
      }
    end  
  end    
end
destroy() click to toggle source
# File app/controllers/followings_controller.rb, line 70
def destroy
  if params[:id].to_i == 0
    destroyed_following = current_user.followings.find(:first, :conditions => {:followed_id => params[:item_id].to_i , :followed_type => params[:item_type]})  
  else
    destroyed_following = Following.find(params[:id])
  end  
  @item = destroyed_following.followed
  if destroyed_following.present? && destroyed_following.destroy
    respond_to do |format|
      format.html {
        @following = Following.new
        # redirect_back_or_default(root_path)
        render :template => 'followings/update_all', :locals => {:item => destroyed_following.followed, :action => 'create'}, :layout => !request.xhr?          
      }
      format.json {
        render :action => 'follow.json', :layout => false
      }
      format.floki {
        render :action => 'follow.json', :layout => false
      }
    end  
  else
    respond_to do |format|
      format.html {
        render :nothing => true, :status => :error  
      }
      format.json {
        render :action => 'follow.json', :layout => false
      }
      format.floki {
        render :action => 'follow.json', :layout => false
      }
    end  
  end    
end
index() click to toggle source
# File app/controllers/followings_controller.rb, line 25
def index
  if params[:user_id]
    @user = User.find(params[:user_id])
    @following_politicians = @user.following_politicians
    @following_areas = @user.following_areas        
  else
    redirect_to logged_in? ? account_path : root_url
  end
end
state() click to toggle source
# File app/controllers/followings_controller.rb, line 106
def state
  @item = params[:type].constantize.find(params[:id])
  render :action => "follow_state.json", :layout => false
end