Class: Admin::TextAssetsController

Inherits:
ResourceController
  • Object
show all
Defined in:
app/controllers/admin/text_assets_controller.rb

Instance Method Summary collapse

Instance Method Details

#uploadObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/admin/text_assets_controller.rb', line 10

def upload
  if !request.post?  # not a POST request
    render :template => "site/not_found", :status => :method_not_allowed

  elsif params[:upload].nil?  # necessary params are missing
    render :text => '', :status => :bad_request

  else
    @text_asset = model_class.create_from_file(params[:upload][:file])

    if @text_asset.new_record?  # wasn't saved -- there must be errors
      responds_to_parent do
        render :update do |page|
          # populate errors in the errors popup and call method to show
          page.replace_html "errors_for_#{model_symbol}",
              '<ul class="uploadErrors">' +
              @text_asset.errors.collect{|k,v|
                %{<li class="warning">#{k.humanize.titlecase}: #{v}</li>}
              }.to_s +
              '</ul>'
          page.call('showErrorsPopup')
        end
      end

    else  # success!
      # AbstractController methods aren't available within parent/render
      # blocks so call #model_index_url now to use from inside
      index_url = send("admin_#{model_symbol}s_url")
      responds_to_parent do
        render :update do |page|
          page.redirect_to index_url
        end
      end

    end

  end
end