Class TagsController
In: app/controllers/tags_controller.rb
Parent: ApplicationController

Controlador para los tags

Methods

index   show  

Public Instance methods

Listado de tags

[Source]

    # File app/controllers/tags_controller.rb, line 5
 5:   def index
 6:     @title_for_head = t('tags.Tags')
 7:     conditions = "draft='f' AND published_at <= '#{Time.now.strftime('%Y-%m-%d %H:%M')}' "
 8:     
 9:     @ttype = params[:type]
10:     
11:     # Deberia ser así
12:     # all_tags = Document.tag_counts(:conditions => conditions)
13:     
14:     all_tags = Document.in_irekia.published.tag_counts(:conditions => conditions)    
15:     @tags = all_tags.sort! {|a, b| b.count <=> a.count}[0..100].sort! {|a, b| a.sanitized_name <=> b.sanitized_name}
16: 
17:   end

Contenidos taggeados con un tag

[Source]

    # File app/controllers/tags_controller.rb, line 20
20:   def show
21:     if params[:id].match(/^_/)
22:       tags = Tag.find_all_by_sanitized_name_es(params[:id])
23:     else
24:       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]])
25:     end
26: 
27:     if tags.empty?
28:       flash[:notice] = "No hay nada con el tag #{params[:id]}"
29:       redirect_to tags_path and return
30:     else
31:       @title = t("tags.Documentos_con_tag", :tag => tags.first.name)
32:       @title_for_head = @title
33:     end
34: 
35:     tag_ids = tags.collect(&:id)
36: 
37:     conditions = "tag_id in (#{tag_ids.join(', ')})"
38:     
39:     if params[:type].present? && !params[:type].eql?("all") && taggable_modules.collect(&:to_s).include?(params[:type])
40:       # # Warning: it is ordered by the tagging date, not the publication of the item
41:       # if document_subclasses.include?(params[:type].constantize)
42:       #   @taggings = Tagging.paginate :page => params[:page] || 1,
43:       #                                :conditions => conditions + " AND taggable_type='Document'",
44:       #                                :joins => "inner join documents on (documents.id=taggings.taggable_id AND documents.type='#{params[:type].constantize}')",
45:       #                                :order => "created_at DESC"
46:       # else
47:       #   @taggings = Tagging.paginate :page => params[:page] || 1,
48:       #                                :conditions => conditions + " AND taggable_type='#{params[:type].constantize}'",
49:       #                                :order => "created_at DESC"        
50:       # end
51:       @taggings = paginated_collection_of_tags_for(conditions, {:page => params[:page] || 1}, params[:type])
52:     else
53:       @taggings = paginated_collection_of_tags_for(conditions, {:page => params[:page] || 1})
54:     end
55:     
56:     # @taggings = paginated_collection_of_tags_for(conditions, :page => params[:page] || 1)
57:       
58:     respond_to do |format|
59:       format.html do        
60:         if @taggings.length == 1
61:           taggable = @taggings.first.taggable
62:           if taggable.is_a?(Photo)
63:             redirect_to album_photo_path(taggable.albums.first, taggable)
64:           else
65:             redirect_to taggable and return
66:           end
67:         end
68:       end
69:     end
70:   end

[Validate]