0

When I run the retrieve method I get undefined method split for nil class even though my class is defined. I could really use some help with get this to work. The command is called donate but for some reason it is not getting called.

This is my donation box which calls a c++ program

module DonationboxesHelper

   private
      def editCommons(type)
         boxFound = Donationbox.find_by_id(params[:id])
         if(boxFound)
            logged_in = current_user
            if(logged_in && ((logged_in.id == boxFound.user_id) || logged_in.admin))
               if(type == "update")
                  boxFound.initialized_on = currentTime
               end
               @donationbox = boxFound
               @user = User.find_by_vname(boxFound.user.vname)
               if(type == "update")
                  if(logged_in.admin || !boxFound.turn_on)
                     if(@donationbox.update_attributes(params[:donationbox]))
                        flash[:success] = "#{@user.vname}'s donationbox was successfully updated."
                        redirect_to user_path(@user)
                     else
                        render "edit"
                     end
                  else
                     redirect_to root_path
                  end
               elsif(type == "retrieve")
                  if(logged_in.id == boxFound.user_id && boxFound.hit_goal)
                     pouch = Pouch.find_by_user_id(@user.id)
                     points = @donationbox.progress

#                     string_array = calculator(newPet.hp, newPet.atk, newPet.def, newPet.spd)
#petCost, petLevel = string_array.map { |str| str.to_i}

                     #Calculate the tax
                     points = 1000
                     results = `Resources/Code/donationbox/donate #{points}`
                     string_array = results.split(",")
                     pointsTax, taxRate = string_array.map{|str| str.to_f}

                     #Send the points to the user's pouch
                     netPoints = @donationbox.progress - pointsTax
                     pouch.amount += netPoints
                     @pouch = pouch
                     @pouch.save
                     @donationbox.progress = 0
                     @donationbox.goal = 0
                     @donationbox.hit_goal = false
                     @donationbox.turn_on = false
                     @donationbox.save
                     redirect_to user_path(@user)
                  else
                     redirect_to root_path
                  end
               elsif(type == "refund")
                  if(logged_in.admin || !boxFound.hit_goal)
                     #Retrieve all donations
                     allDonors = Donor.all
                     boxDonors = allDonors.select{|donor| donor.donationbox_id == boxFound.id}
                     activeDonors = boxDonors.select{|donor| donor.created_on > boxFound.initialized_on}

                     #Gives back the original users donations
                     activeDonors.each do |donor|
                        donor.user.pouch.amount += donor.amount
                        boxFound.progress -= donor.amount
                        @donationbox = boxFound
                        @donationbox.save
                        @pouch = donor.user.pouch
                        @pouch.save
                        @donor = donor
                        @donor.destroy
                     end
                     boxFound.turn_on = false
                     boxFound.goal = 0
                     boxFound.progress = 0
                     if(boxFound.hit_goal)
                        boxFound.hit_goal = false
                     end
                     @donationbox = boxFound
                     @donationbox.save
                     redirect_to user_path(@donationbox.user)
                  else
                     redirect_to root_path
                  end
               end
            else
               redirect_to root_path
            end
         else
            render "public/404"
         end
      end

      def mode(type)
         if(timeExpired)
            logout_user
            redirect_to root_path
         else
            if(type == "index")
               logged_in = current_user
               if(logged_in && logged_in.admin)
                  allBoxes = Donationbox.order("initialized_on desc")
                  @donationboxes = Kaminari.paginate_array(allBoxes).page(params[:page]).per(10)
               else
                  redirect_to root_path
               end
            elsif(type == "edit" || type == "update" || type == "retrieve" || type == "refund")
               if(current_user && current_user.admin)
                  editCommons(type)
               else
                  allMode = Maintenancemode.find_by_id(1)
                  userMode = Maintenancemode.find_by_id(5)
                  if(allMode.maintenance_on || userMode.maintenance_on)
                     if(allMode.maintenance_on)
                        render "/start/maintenance"
                     else
                        render "/users/maintenance"
                     end
                  else
                     editCommons(type)
                  end
               end
            end
         end
      end
end

Upon running the command it errors out.

On top of this I get this error when I try to make it look like this:

eric@eric-PORTEGE-R830:~/Projects/Local/Websites/Resources/C++code/donationbox$ donate 200
donate: command not found

The other issue is it only works when I do ./donate I want to use donate instead of this but am unable to.

Eric
  • 25
  • 6
  • I assume you must provide a full path to the c++ executable file. – Roman Kiselenko Sep 10 '17 at 07:31
  • I am using a linker called Resources as part of the path. Every other section allows me to call resources file to find the data without having to give the full path. – Eric Sep 10 '17 at 17:12

1 Answers1

0

On top of this I get this error when I try to make it look like this:

eric@eric-PORTEGE-R830:~/Projects/Local/Websites/Resources/C++code/donationbox$ donate 200 donate: command not found

The other issue is it only works when I do ./donate I want to use donate instead of this but am unable to.

If you want be able to run the application using donate, you need to add a path to directory where donate is placed to PATH environment variable (here it is described)

Alex
  • 9,891
  • 11
  • 53
  • 87
  • Can you help me out a bit? I don't really know how to do this in Linux effectively. I don't even know where the profile of my section is. I need more clarifications. – Eric Sep 10 '17 at 17:14
  • @Eric Try to print the `$PATH` variable content from your application, because it may run different environment. – Alex Sep 11 '17 at 06:45