Project-Rails/app/controllers/concerns/applications.rb
# XXX: Only file uploading part is ready. Record updating need to be done
#      Besides, you may want rename the file instead of using it's original name
# XXX: How to allow uploading multiple files???
# XXX: Javascript: 1) make sure at least one animal has been surrendered
#                  2) verify "user_id", "age", "phone", "email", "postal_code", "income" field
#                  3) if user exists, set all fields' values to the existing values
#                  4) display request's response (@status)
#                  5) redirect page and update @status
# get 'applications/surrender' => 'petshelter#app_surrender'
Only file uploading part is ready.
Only file uploading part is ready .
def app_surrender
    prepareBaseContext
    @animal = Animal.take!
    @people = People.take!
    if request.method == 'POST'
      uploaded_io = params[:photo]
      if uploaded_io != nil
        folder = ''
        if ['.jpg', '.png', '.gif', '.bmp'].include? File.extname(uploaded_io.original_filename)
          folder = 'images'
        elsif ['.wav', '.mp3', '.ogg'].include? File.extname(uploaded_io.original_filename)
          folder = 'audios'
        elsif ['.mp4', '.ogg', '.webm'].include? File.extname(uploaded_io.original_filename)
          folder = 'videos'
        end
        File.open(Rails.root.join('public', folder, uploaded_io.original_filename), 'wb') do |file|
          file.write(uploaded_io.read)
        end
      end
    end
    render 'petshelter/applications/surrender'
  end
def app_surrender prepareBaseContext @animal = Animal . take! @people = People . take! if request . method == 'POST' uploaded_io = params [ :photo ] if uploaded_io != nil folder = '' if [ '.jpg' , '.png' , '.gif' , '.bmp' ] . include? File . extname ( uploaded_io . original_filename ) folder = 'images' elsif [ '.wav' , '.mp3' , '.ogg' ] . include? File . extname ( uploaded_io . original_filename ) folder = 'audios' elsif [ '.mp4' , '.ogg' , '.webm' ] . include? File . extname ( uploaded_io . original_filename ) folder = 'videos' end File . open ( Rails . root . join ( 'public' , folder , uploaded_io . original_filename ) , 'wb' ) do | file | file . write ( uploaded_io . read ) end end end render 'petshelter/applications/surrender' end
XXX: Only file uploading part is ready.
XXX : Only file uploading part is ready .