Class: Spree::Admin::ActionText::VideoEmbedsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/spree/admin/action_text/video_embeds_controller.rb

Instance Method Summary collapse

Methods included from BreadcrumbConcern

#add_breadcrumb_icon_instance_var

Instance Method Details

#createObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/spree/admin/action_text/video_embeds_controller.rb', line 7

def create
  oembed_response = oembed_cached_response(params[:url])

  video_embed = ::ActionText::VideoEmbed.new(url: params[:url])
  video_embed.raw_html = oembed_response.html
  video_embed.thumbnail_url = oembed_response.thumbnail_url

  if video_embed.save
    content = render_to_string(
      partial: 'action_text/video_embeds/thumbnail',
      locals: { video_embed: video_embed },
      formats: [:html]
    )

    render json: { sgid: video_embed.attachable_sgid, content: content }, status: :created
  else
    render json: { error: video_embed.errors.full_messages.to_sentence }, status: :unprocessable_content
  end
end

#destroyObject



27
28
29
# File 'app/controllers/spree/admin/action_text/video_embeds_controller.rb', line 27

def destroy
  ::ActionText::VideoEmbed.from_attachable_sgid(params[:id]).destroy
end