Class: MediaController

Inherits:
ApplicationController show all
Defined in:
app/controllers/media_controller.rb

Instance Method Summary (collapse)

Methods inherited from ApplicationController

#after_sign_in_path_for, #allow_cors, #auth!, #check_for_initial_install, #compute_pending_moderation, #current_ability, #current_accessor, #current_screen, #http_basic_user_name_and_password, #precompile_error_catch, #process_notification, #restart_webserver, #screen_api, #set_locale, #set_time_zone, #set_version, #sign_in_screen, #sign_out_screen, #switch_to_main_app_ability, #switch_to_plugin_ability, #use_plugin_ability, #webserver_supports_restart?

Instance Method Details

- (Object) create

POST /media Save the graphics that we are going to preview as media without a corresponding graphic model and return the id so we can use it for the preview process. This is ajax posted from the graphic form.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/media_controller.rb', line 15

def create
  auth!(:object => Media, :action => :create)
  @media = Media.new(:file => media_params[:graphic][:media_attributes]["0"][:file])

  if @media.file_size > 0 && Concerto::ContentConverter.supported_types.include?(@media.file_type)
     medias = Concerto::ContentConverter.convert([@media])
     @media = medias.select { |m| m.key == 'processed' }.first
  end

  @media.attachable_id = 0  # this is assigned to the actual Graphic record when the graphic is saved
  @media.attachable_type = 'Content'
  @media.key = 'preview'

  if @media.save
    # jquery.iframe-transport requires result sent back in textarea
    render :inline  => "<textarea data-type='application/json'>#{@media.to_json(:only => :id)}</textarea>" 
  else
    raise 'Problem saving media ' + @media.errors.full_messages.join("; ")
  end
end

- (Object) media_params



36
37
38
# File 'app/controllers/media_controller.rb', line 36

def media_params
  params.permit(:graphic => [ :media_attributes => [ :file, :key ] ])
end

- (Object) show

GET /media/1



5
6
7
8
9
# File 'app/controllers/media_controller.rb', line 5

def show
  # TODO this needs to be secured
  @media = Media.find(params[:id])
  send_data @media.file_contents, :filename => @media.file_name, :type => @media.file_type, :disposition => 'inline'
end