Class: TagsController
- Inherits:
-
BaseController
- Object
- ApplicationController
- BaseController
- TagsController
- Defined in:
- app/controllers/tags_controller.rb
Instance Method Summary collapse
- #auto_complete_for_tag_name ⇒ Object
- #cache_action? ⇒ Boolean
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #manage ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Methods inherited from BaseController
#advertise, #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
#auto_complete_for_tag_name ⇒ Object
11 12 13 14 |
# File 'app/controllers/tags_controller.rb', line 11 def auto_complete_for_tag_name @tags = ActsAsTaggableOn::Tag.find(:all, :limit => 10, :conditions => [ 'LOWER(name) LIKE ?', '%' + (params[:id] || params[:tag_list]) + '%' ]) render :inline => "<%= auto_complete_result(@tags, 'name') %>" end |
#cache_action? ⇒ Boolean
7 8 9 |
# File 'app/controllers/tags_controller.rb', line 7 def cache_action? !logged_in? && params[:type].blank? end |
#destroy ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/controllers/tags_controller.rb', line 54 def destroy @tag = ActsAsTaggableOn::Tag.find_by_name(URI::decode(params[:id])) @tag.destroy respond_to do |format| format.html { flash[:notice] = :tag_was_successfully_deleted.l redirect_to } format.xml { render :nothing => true } end end |
#edit ⇒ Object
35 36 37 |
# File 'app/controllers/tags_controller.rb', line 35 def edit @tag = ActsAsTaggableOn::Tag.find_by_name(URI::decode(params[:id])) end |
#index ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/controllers/tags_controller.rb', line 16 def index @tags = (100) @user_tags = (75, 'User') @post_tags = (75, 'Post') @photo_tags = (75, 'Photo') @clipping_tags = (75, 'Clipping') end |
#manage ⇒ Object
28 29 30 31 32 |
# File 'app/controllers/tags_controller.rb', line 28 def manage @search = ActsAsTaggableOn::Tag.search(params[:search]) @search. ||= 'name.asc' @tags = @search.page(params[:page]).per(100) end |
#show ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'app/controllers/tags_controller.rb', line 67 def show tag_array = ActsAsTaggableOn::TagList.from( URI::decode(params[:id]) ) @tags = ActsAsTaggableOn::Tag.find(:all, :conditions => [ 'name IN (?)', tag_array ] ) if @tags.nil? || @tags.empty? flash[:notice] = :tag_does_not_exists.l_with_args(:tag => tag_array) redirect_to :action => :index and return end @related_tags = @tags.first. @tags_raw = @tags.collect { |t| t.name } .join(',') if params[:type] case params[:type] when 'Post', 'posts' @pages = @posts = Post.recent.tagged_with(tag_array).page(params[:page]).per(20) @photos, @users, @clippings = [], [], [] when 'Photo', 'photos' @pages = @photos = Photo.recent.tagged_with(tag_array).page(params[:page]).per(30) @posts, @users, @clippings = [], [], [] when 'User', 'users' @pages = @users = User.recent.tagged_with(tag_array).page(params[:page]).per(30) @posts, @photos, @clippings = [], [], [] when 'Clipping', 'clippings' @pages = @clippings = Clipping.recent.tagged_with(tag_array).page(params[:page]).per(10) @posts, @photos, @users = [], [], [] else @clippings, @posts, @photos, @users = [], [], [], [] end else @posts = Post.recent.limit(5).tagged_with(tag_array) @photos = Photo.recent.limit(10).tagged_with(tag_array) @users = User.recent.limit(10).tagged_with(tag_array) @clippings = Clipping.recent.limit(10).tagged_with(tag_array) end end |
#update ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/controllers/tags_controller.rb', line 39 def update @tag = ActsAsTaggableOn::Tag.find_by_name(URI::decode(params[:id])) respond_to do |format| if @tag.update_attributes(params[:tag]) flash[:notice] = :tag_was_successfully_updated.l format.html { redirect_to } format.xml { render :nothing => true } else format.html { render :action => "edit" } format.xml { render :xml => @tag.errors.to_xml } end end end |