Class: Concen::GridFilesController

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

Instance Method Summary collapse

Instance Method Details

#createObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/concen/grid_files_controller.rb', line 8

def create
  @page = Page.find(params[:page_id])
  @grid_file = @page.grid_files.build
  filename = params[:filename]
  if ["css", "js"].include?(params[:file_type])
    unless MIME::Types.type_for(filename).first.to_s.include?(params[:file_type])
      filename << "." + params[:file_type]
    end
  end
  if @grid_file.store("", filename)
    content = render_to_string(:partial => "concen/pages/files")
    render :json => {:success => true, :content => content}
  else
    render :json => {:success => false}
  end
end

#destroyObject



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/concen/grid_files_controller.rb', line 40

def destroy
  @page = Page.find(params[:page_id])
  @grid_file = @page.grid_files.find(params[:id])
  respond_to do |format|
    if @grid_file.destroy
      format.html { redirect_to edit_concen_page_path(@page) }
      format.json { render :json => {:success => true} }
    else
      format.html { redirect_to edit_concen_page_path(@page) }
      format.json { render :json => {:success => false} }
    end
  end
end

#editObject



25
26
27
28
# File 'app/controllers/concen/grid_files_controller.rb', line 25

def edit
  @page = Page.find(params[:page_id])
  @grid_file = @page.grid_files.find(params[:id])
end

#newObject



3
4
5
6
# File 'app/controllers/concen/grid_files_controller.rb', line 3

def new
  @page = Page.find(params[:page_id])
  @grid_file = @page.grid_files.build
end

#updateObject



30
31
32
33
34
35
36
37
38
# File 'app/controllers/concen/grid_files_controller.rb', line 30

def update
  @page = Page.find(params[:page_id])
  @grid_file = @page.grid_files.find(params[:id])
  if @grid_file.store(params[:concen_grid_file_page], @grid_file.original_filename)
    redirect_to edit_concen_page_grid_file_path(@page, @grid_file)
  else
    render :edit
  end
end

#uploadObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/concen/grid_files_controller.rb', line 54

def upload
  # logger.info { "----#{env['rack.input']}" }
  # logger.info { "----#{env['HTTP_X_FILE_NAME']}" }
  # logger.info { "----#{env['CONTENT_TYPE']}" }
  @page = Page.find(params[:page_id])
  @grid_file = @page.grid_files.build
  if env["rack.input"]
    file = env["rack.input"]
    filename = CGI::unescape(env["HTTP_X_FILE_NAME"])
  else
    file = params[:qqfile].read
    filename = params[:qqfile].original_filename
  end
  if @grid_file.store(file, filename)
    content = render_to_string(:partial => "concen/pages/files")
    render :json => {:success => true, :content => content}
  end
end