DevelopingCoder/cs61a_hintr

View on GitHub
app/controllers/uploads_controller.rb

Summary

Maintainability
A
0 mins
Test Coverage
class UploadsController < ApplicationController
    
    def new
        #Based on file being uploaded, redirect to its upload controller
        if not params.has_key?("file")
            flash[:notice] = "Please attach a file"
            render :index and return
        end
        file_type = params[:file_type].split()[0].downcase #(ie Concepts, Tags)
        
        #No confirmation on Users
        if file_type == "users"
            flash[:notice] = User.import(current_user, File.open(params[:file].tempfile))
            render :index
        else
            redirect_to(controller: "upload_" + file_type, action: :show, path: params[:file].path)
        end
    end
end