Class: Wco::TagsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Wco::TagsController
- Defined in:
- app/controllers/wco/tags_controller.rb
Instance Method Summary collapse
- #add_to ⇒ Object
- #add_to_many ⇒ Object
- #create ⇒ Object
- #create_for_sidebar ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #new_for_sidebar ⇒ Object
- #remove_from ⇒ Object
- #remove_from_many ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#add_to ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/wco/tags_controller.rb', line 65 def add_to @tag = Wco::Tag.find params[:id] resource = params[:resource].constantize.find params[:resource_id] :update, @tag resource..push @tag flag = resource.save flash_notice 'maybe?' redirect_to request.referrer end |
#add_to_many ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/controllers/wco/tags_controller.rb', line 76 def add_to_many @tag = Wco::Tag.find params[:id] resources = params[:resource].constantize.find params[:resource_ids] :update, @tag flags = [] resources.each do |resource| resource..push @tag flags.push resource.save end flash_notice flags # redirect_to request.referrer end |
#create ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'app/controllers/wco/tags_controller.rb', line 6 def create @tag = Wco::Tag.new params[:tag].permit! :create, @tag if @tag.save flash_notice "created tag" else flash_alert "Cannot create tag: #{@tag.errors.}" end redirect_to action: 'index' end |
#create_for_sidebar ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'app/controllers/wco/tags_controller.rb', line 56 def :create, Wco::Tag @current_profile..push Wco::Tag.find(params[:tag_id]) @current_profile.save flash_notice 'Ok' redirect_to request.referrer end |
#destroy ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'app/controllers/wco/tags_controller.rb', line 17 def destroy @tag = Wco::Tag.find params[:id] :destroy, @tag if @tag.destroy flash_notice 'ok' else flash_alert 'No luck.' end redirect_to request.referrer end |
#edit ⇒ Object
28 29 30 31 |
# File 'app/controllers/wco/tags_controller.rb', line 28 def edit @tag = Wco::Tag.find params[:id] :edit, @tag end |
#index ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/wco/tags_controller.rb', line 33 def index :index, Wco::Tag @tags = Wco::Tag.all.order_by( slug: :asc ) = Wco::Tag.all.to_a.group_by(&:parent_id) build_tree = lambda do |parent_id| ([parent_id] || []).sort_by { |tag| tag.slug.downcase }.map do |tag| { tag: tag, sons: build_tree.call(tag.id) } end end @tree = build_tree.call(nil) @template = params[:template] || 'index_tree' end |
#new ⇒ Object
49 50 51 |
# File 'app/controllers/wco/tags_controller.rb', line 49 def new :new, Wco::Tag end |
#new_for_sidebar ⇒ Object
53 54 55 |
# File 'app/controllers/wco/tags_controller.rb', line 53 def :new, Wco::Tag end |
#remove_from ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# File 'app/controllers/wco/tags_controller.rb', line 90 def remove_from @tag = Wco::Tag.find params[:id] resource = params[:resource].constantize.find params[:resource_id] :update, @tag resource..delete @tag flag = resource.save flash_notice 'maybe?' redirect_to request.referrer end |
#remove_from_many ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/controllers/wco/tags_controller.rb', line 101 def remove_from_many @tag = Wco::Tag.find params[:id] resources = params[:resource].constantize.find params[:resource_ids] :update, @tag flags = [] resources.each do |resource| resource..delete @tag flags.push resource.save end flash_notice flags # redirect_to request.referrer end |
#show ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'app/controllers/wco/tags_controller.rb', line 115 def show @tag = Wco::Tag.find params[:id] :show, @tag @galleries = @tag.galleries.page( params[:galleries_page] ).per( current_profile.per_page ) @leads = @tag.leads.page( params[::Wco::Lead::PAGE_PARAM_NAME] ).per( current_profile.per_page ) @leadsets = @tag.leadsets.page( params[::Wco::Leadset::PAGE_PARAM_NAME] ).per( current_profile.per_page ) @reports = @tag.reports.page( params[:reports_page] ).per( current_profile.per_page ) @conversations, @messages, _ = WcoEmail::Conversation.( {tagname: @tag.slug}, current_profile ) # render params['template'] || 'show' end |
#update ⇒ Object
129 130 131 132 133 134 135 136 137 138 |
# File 'app/controllers/wco/tags_controller.rb', line 129 def update @tag = Wco::Tag.find params[:id] :update, @tag if @tag.update params[:tag].permit! flash_notice "updated tag" else flash_alert "Cannot update tag: #{@tag.errors.}" end redirect_to action: 'index' end |