Module: ResourcesController::ActsAsPublishedConcern

Extended by:
ActiveSupport::Concern
Defined in:
app/concerns/resources_controller/acts_as_published_concern.rb

Instance Method Summary collapse

Instance Method Details

#publish_manyObject


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/concerns/resources_controller/acts_as_published_concern.rb', line 5

def publish_many
  @collection = load_collection_scope.find(params[:ids])
  @collection.map(&:publish!)

  resource_labels = []
  @collection.each do |resource|
    [:human, :name, :title, :email, :to_s].each do |method_name|
      if resource.respond_to?(method_name)
        resource_labels << resource.send(method_name)
        break
      end
    end
  end

  notice = I18n.t("acts_as_published.notices.published_many", names: resource_labels.to_sentence)
  if Rails.version < '5.0.0'
    redirect_to :back, notice: notice
  else
    flash[:notice] = notice
    redirect_back(fallback_location: main_app.root_path)
  end
end

#toggle_publishedObject


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/concerns/resources_controller/acts_as_published_concern.rb', line 51

def toggle_published
  @resource = load_resource
  @resource.toggle_published!

  action_taken = @resource.published? ? 'published' : 'unpublished'
  
  resource_label = nil
  [:human, :name, :title, :email, :to_s].each do |method_name|
    if @resource.respond_to?(method_name)
      resource_label = @resource.send(method_name)
      break
    end
  end

  if Rails.version < '5.0.0'
    redirect_to :back, notice: I18n.t("acts_as_published.notices.#{action_taken}", name: resource_label)
  else
    flash[:notice] = I18n.t("acts_as_published.notices.#{action_taken}", name: resource_label)
    redirect_back(fallback_location: main_app.root_path)
  end
end

#unpublish_manyObject


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/concerns/resources_controller/acts_as_published_concern.rb', line 28

def unpublish_many
  @collection = load_collection_scope.find(params[:ids])
  @collection.map(&:unpublish!)

  resource_labels = []
  @collection.each do |resource|
    [:human, :name, :title, :email, :to_s].each do |method_name|
      if resource.respond_to?(method_name)
        resource_labels << resource.send(method_name)
        break
      end
    end
  end

  notice = I18n.t("acts_as_published.notices.unpublished_many", names: resource_labels.to_sentence)
  if Rails.version < '5.0.0'
    redirect_to :back, notice: notice
  else
    flash[:notice] = notice
    redirect_back(fallback_location: main_app.root_path)
  end
end