Class: Railspress::Api::V1::PostHeaderImageContextsController

Inherits:
BaseController
  • Object
show all
Includes:
Concerns::PostSerialization
Defined in:
app/controllers/railspress/api/v1/post_header_image_contexts_controller.rb

Instance Attribute Summary

Attributes inherited from BaseController

#current_api_key

Instance Method Summary collapse

Instance Method Details

#destroyObject



41
42
43
44
45
46
47
48
49
# File 'app/controllers/railspress/api/v1/post_header_image_contexts_controller.rb', line 41

def destroy
  @post.clear_image_override(@context_name, :header_image)
  @post.save!

  render json: {
    data: serialize_header_image_context(@post, @context_name, context_config: @context_config),
    post: serialize_post(@post.reload)
  }
end

#indexObject



17
18
19
20
21
22
23
# File 'app/controllers/railspress/api/v1/post_header_image_contexts_controller.rb', line 17

def index
  render json: {
    data: available_contexts.map do |context_name, context_config|
      serialize_header_image_context(@post, context_name, context_config: context_config)
    end
  }
end

#showObject



25
26
27
# File 'app/controllers/railspress/api/v1/post_header_image_contexts_controller.rb', line 25

def show
  render json: { data: serialize_header_image_context(@post, @context_name, context_config: @context_config) }
end

#updateObject



29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/railspress/api/v1/post_header_image_contexts_controller.rb', line 29

def update
  apply_context_override!
  return if performed?

  render json: {
    data: serialize_header_image_context(@post, @context_name, context_config: @context_config),
    post: serialize_post(@post.reload)
  }
rescue ActiveSupport::MessageVerifier::InvalidSignature, ActiveRecord::RecordNotFound
  render_error("Invalid signed blob id.", status: :unprocessable_content)
end