class TagsController

Controlador para los tags

Public Instance Methods

index() click to toggle source

Listado de tags

# File app/controllers/tags_controller.rb, line 28
def index
  @title = t('tags.title')
  conditions = "published_at <= '#{Time.now.strftime('%Y-%m-%d %H:%M')}' "
  
  @ttype = params[:type]
  
  all_tags = Document.published.tag_counts(:conditions => conditions)    
  @tags = all_tags.sort! {|a, b| b.count <=> a.count}[0..100].sort! {|a, b| a.sanitized_name <=> b.sanitized_name}
end
show() click to toggle source

Contenidos taggeados con un tag

# File app/controllers/tags_controller.rb, line 39
  def show
    if params[:id].match(/^_/)
      tags = Tag.find_all_by_sanitized_name_es(params[:id])
    elsif params[:id].match(/^\d+$/)
      tags = [Tag.find(params[:id])]
    else
      tags = Tag.find_by_sql(["SELECT * FROM tags WHERE (sanitized_name_es=? OR sanitized_name_eu=? OR sanitized_name_en=?)", params[:id], params[:id], params[:id]])
    end
    if tags.empty?
      render :template => '/site/notfound.html', :status => 404 and return
    else                           
      session[:criterio_id] = nil       
      @tag = tags.first          
      @sort = 'date'
# TODO: temp fix
      if @tag.criterio_id.present?
        #if @tag.updated_at > @criterio.updated_at
        #  @tag.criterio.update_attribute(:title, @tag.criterio_title)
        #end
        @criterio = Criterio.find_by_id(@tag.criterio_id)
      else
        @criterio = Criterio.create(:title => @tag.criterio_title, :ip => request.remote_ip)
        # @tag.create_criterio(:title => @tag.criterio_title, :ip => request.remote_ip)
        @tag.update_attribute(:criterio_id, @criterio.id)
      end
      
      unless @tag.criterio_id.present? && !@criterio.nil?                                              
        title = @tag.criterio_title
        title << " AND type: #{params[:type].downcase}" if params[:type].present? && !params[:type].eql?('all')
        @criterio = Criterio.create(:title => title, :parent_id => nil, :ip => request.remote_ip)
        redirect_to search_url(:id => @criterio.id) and return
      end
      if params[:type].present? && !params[:type].eql?('all')
        @criterio.title << " AND type: #{params[:type].downcase}"
      end
      set_query
      unless do_elasticsearch_and_save_results(true, false)
        redirect_to elasticsearch_not_available_redirect_url and return
      end  
      render :template => '/search/show' and return       
    end
  end