Class: Cms::ContentBlockController

Inherits:
BaseController show all
Includes:
ContentRenderingSupport, PublishWorkflow
Defined in:
app/controllers/cms/content_block_controller.rb

Instance Method Summary collapse

Methods included from ContentRenderingSupport

#handle_access_denied_on_page, #handle_draft_not_found, #handle_not_found_on_page, #handle_server_error_on_page, #show_content_as_page

Methods inherited from BaseController

allow_guests_to

Methods inherited from ApplicationController

#no_browser_caching

Instance Method Details

#bulk_updateObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/cms/content_block_controller.rb', line 25

def bulk_update
  ids = params[:content_id] || []
  models = ids.collect do |id|
    model_class.find(id.to_i)
  end
  if params[:commit] == 'Delete'
    deleted = models.select do |m|
      m.destroy
    end
    flash[:notice] = "Deleted #{deleted.size} records."
  else
    # Need to do these one at a time since the code logic is more complex than single UPDATE.
    published = models.select do |m|
      m.publish!
    end

    flash[:notice] = "Published #{published.size} records."
  end

  redirect_to action: :index
end

#createObject



74
75
76
77
78
79
80
81
82
83
# File 'app/controllers/cms/content_block_controller.rb', line 74

def create
  if create_block
    after_create_on_success
  else
    after_create_on_failure
  end
rescue Exception => @exception
  raise @exception if @exception.is_a?(Cms::Errors::AccessDenied)
  after_create_on_error
end

#destroyObject



102
103
104
105
106
107
108
109
# File 'app/controllers/cms/content_block_controller.rb', line 102

def destroy
  do_command("deleted") { @block.destroy }
  respond_to do |format|
    format.html { redirect_to_first params[:_redirect_to], engine_aware_path(@block.class) }
    format.json { render :json => {:success => true} }
  end

end

#editObject



85
86
87
# File 'app/controllers/cms/content_block_controller.rb', line 85

def edit
  load_block_draft
end

#indexObject



21
22
23
# File 'app/controllers/cms/content_block_controller.rb', line 21

def index
  load_blocks
end

#inlineObject

Getting the content for the editing frame.



64
65
66
67
# File 'app/controllers/cms/content_block_controller.rb', line 64

def inline
  load_block_draft
  render_block_in_main_container
end

#newObject



69
70
71
72
# File 'app/controllers/cms/content_block_controller.rb', line 69

def new
  build_block
  set_default_category
end

#new_button_pathObject



141
142
143
# File 'app/controllers/cms/content_block_controller.rb', line 141

def new_button_path
  new_engine_aware_path(content_type)
end

#publishObject

Additional CMS Action



113
114
115
116
# File 'app/controllers/cms/content_block_controller.rb', line 113

def publish
  do_command("published") { @block.publish! }
  redirect_to_first params[:_redirect_to], engine_aware_path(@block, nil)
end

#revert_toObject



118
119
120
121
122
123
# File 'app/controllers/cms/content_block_controller.rb', line 118

def revert_to
  do_command("reverted to version #{params[:version]}") do
    revert_block(params[:version])
  end
  redirect_to_first params[:_redirect_to], engine_aware_path(@block, nil)
end

#showObject

Getting content by its id (i.e. /products/:id) Logged in editors will get the editing frame.



58
59
60
61
# File 'app/controllers/cms/content_block_controller.rb', line 58

def show
  load_block_draft
  render_editing_frame_or_block_in_main_container
end

#show_via_slugObject

Getting content by its path (i.e. /products/:slug)



48
49
50
51
52
53
54
# File 'app/controllers/cms/content_block_controller.rb', line 48

def show_via_slug
  @block = model_class.with_slug(params[:slug])
  unless @block
    raise Cms::Errors::ContentNotFound.new("No Content at #{model_class.calculate_path(params[:slug])}")
  end
  render_block_in_main_container
end

#updateObject



89
90
91
92
93
94
95
96
97
98
99
100
# File 'app/controllers/cms/content_block_controller.rb', line 89

def update
  if update_block
    after_update_on_success
  else
    after_update_on_failure
  end
rescue ActiveRecord::StaleObjectError => @exception
  after_update_on_edit_conflict
rescue Exception => @exception
  raise @exception if @exception.is_a?(Cms::Errors::AccessDenied)
  after_update_on_error
end

#versionObject



125
126
127
128
129
130
131
# File 'app/controllers/cms/content_block_controller.rb', line 125

def version
  load_block
  if params[:version]
    @block = @block.as_of_version(params[:version])
  end
  render "show_in_isolation"
end

#versionsObject



133
134
135
136
137
138
139
# File 'app/controllers/cms/content_block_controller.rb', line 133

def versions
  if model_class.versioned?
    load_block
  else
    render :text => "Not Implemented", :status => :not_implemented
  end
end