Class: CkeditorController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/ckeditor_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /ckeditor/create/:kind



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/ckeditor_controller.rb', line 28

def create
  @kind = params[:kind] || 'file'
  
  unless params[:CKEditor].blank?	  
   params[@swf_file_post_name] = params.delete(:upload)
 end
 
  klass = case @kind.downcase
    when 'file'  then Ckeditor.file_model
	when 'image' then Ckeditor.image_model
 end

 @record = klass.new
 
 options = {}
 
 params.each do |k, v|
   key = k.to_s.downcase
   options[key] = v if @record.respond_to?("#{key}=")
 end
  
  @record.attributes = options
  @record.user ||= current_user if respond_to?(:current_user)
  
  if @record.valid? && @record.save
    @text = params[:CKEditor].blank? ? @record.to_json(:only=>[:id, :type], :methods=>[:url, :content_type, :size, :filename, :format_created_at], :root => "asset") : %Q"<script type='text/javascript'>
      window.parent.CKEDITOR.tools.callFunction(#{params[:CKEditorFuncNum]}, '#{Ckeditor::Utils.escape_single_quotes(@record.url_content)}');
    </script>"
    
    render :text => @text
  else
    render :nothing => true
  end
end

#filesObject

GET /ckeditor/files



18
19
20
21
22
23
24
25
# File 'app/controllers/ckeditor_controller.rb', line 18

def files
  @files = Ckeditor.file_model.find(:all, :order=>"id DESC")
  
  respond_to do |format|
    format.html {}
    format.xml { render :xml=>@files }
  end
end

#imagesObject

GET /ckeditor/images



7
8
9
10
11
12
13
14
15
# File 'app/controllers/ckeditor_controller.rb', line 7

def images
  user_id = current_user.id if (respond_to?(:current_user) && current_user)
  @images = Ckeditor.image_model.find(:all, :order=>"id DESC", :conditions => {:user_id => user_id})
      
  respond_to do |format|
    format.html {}
    format.xml { render :xml=>@images }
  end
end